@Kev

Как поменять у nginx root при определенном url?

Добрый день.

Имеем такой конфиг nginx:
server {
	listen 80;
	server_name test.loc;
	root /var/www/test;
	
	error_log /var/log/nginx/mytest.log;
	index index.html index.php;
	
	location / {
	
	    index index.html index.php;
	    #try_files $uri $uri/ /index.php?$args;
	    set $root /var/www/test;
	}
	
	location /sample {
	   
	    index index.html index.php;
	    #try_files $uri $uri/ /index.php?$args;
	    alias /var/www/test2;
	    
	    
	    location ~ \.php$ {
		include fastcgi_params;
		fastcgi_param PATH_INFO $fastcgi_path_info;
		fastcgi_index index.php;
		fastcgi_param	PATH_TRANSLATED  $document_root$fastcgi_script_name;
		fastcgi_param	SCRIPT_FILENAME $document_root$fastcgi_script_name;
		fastcgi_pass   127.0.0.1:9000;
	    }
	}
	
	location ~ \.php$ {
  
	  include fastcgi_params;
	  fastcgi_param PATH_INFO $fastcgi_path_info;
	  fastcgi_index index.php;
	  fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_script_name;
	  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	  fastcgi_pass   127.0.0.1:9000;
	}
	
}

имеем такую структуру
/var/www/test/index.php
/var/www/test2/index.php
/var/www/test2/sample/index.php

Когда заходим на урл test.loc видим содержимое файла /var/www/test/index.php
Когда заходим на урл test.loc/sample видим содержимое файла /var/www/test2/sample/index.php

Подскажите, пожалуйста, как можно сделать так, чтобы на урлах test.loc/sample* выполнялся файл /var/www/test2/index.php?
На данный момент при смене location, к примеру на qqq, сервер ломится в /var/www/test2/qqq/index.php

Спасибо!
  • Вопрос задан
  • 2471 просмотр
Пригласить эксперта
Ответы на вопрос 1
AterCattus
@AterCattus
Люблю быстрый backend
Может так?
location ~ ^/sample(.*)$ {
    # ...
    alias /var/www/test2/$1;
    # ...
}

дока
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы