K
K
Kev2014-03-12 15:03:54
PHP
Kev, 2014-03-12 15:03:54

How to change nginx root at a specific url?

Good afternoon.
We have the following nginx config:

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;
  }
  
}

we have this structure
/var/www/test/index.php
/var/www/test2/index.php
/var/www/test2/sample/index.php

When we go to the url test.loc we see the contents of the file /var/www/test/index.php
When we go to the url test.loc/sample we see the contents of the file /var/www/test2/sample/index.php
Please tell me how make it so that the /var/www/test2/index.php file is executed on the test.loc/sample* urls?
At the moment, when changing location, for example to qqq, the server breaks in /var/www/test2/qqq/index.php
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Akulovich, 2014-03-13
@AterCattus

Maybe so?

location ~ ^/sample(.*)$ {
    # ...
    alias /var/www/test2/$1;
    # ...
}

dock

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question