我有一个像这样的nginx http服务器配置:
server {
listen 80;
server_name test.loc;
root /var/www/test;
location ~ \.php {
fastcgi_split_path_info ^(.+\.php)(.+)$;
set $fsn /index.php;
if (-f $document_root$fastcgi_script_name){
set $fsn $fastcgi_script_name;
}
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fsn;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fsn;
fastcgi_read_timeout 180;
}
location / {
index index.html index.php;
try_files $uri $uri/ /index.php?$args;
}
location /sample/ {
root /var/www/test2/;
}
}
我想解决http://test.loc/sample
root位于/var/www/test2
文件夹中的问题,但无论我怎么做,都会显示/var/www/test
的内容。
提前谢谢。
UPD:
现在我有了这个配置:
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$ {
#try_files $uri =404;
#fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_split_path_info ^(.+\.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;
}
}
一切正常,但当我收到此网址的内容http://test.loc/sample/
时,我会看到内容/var/www/test2/sample/index.php
。
我希望显示/var/www/test2/index.php
有什么想法吗?感谢。