我有两个目录directory1
在我的服务器上,其他目录里面,还有directory2
一个单个文件 index.php
。
我想访问我index.php
的http://服务器/(/var/www/directory2/index.php
)并且能够directory1
使用http://服务器/测试(var/www/directory1/test
) 例如。
我尝试了该配置,但无法访问该index.php
文件:
server {
server_name server;
index index.php index.html index.htm;
access_log /var/log/nginx/server.access.log;
error_log /var/log/nginx/server.error.log;
location / {
root /var/www/directory1;
}
location ~ ^/index.php$ {
root /var/www/directory2;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV production;
include fastcgi_params;
}
}
谢谢你的帮助 !
答案1
我会做这个简单的:
root /var/www/directory1;
location = / {
root /var/www/directory2;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root/index.php;
fastcgi_param APPLICATION_ENV production;
include fastcgi_params;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param APPLICATION_ENV production;
include fastcgi_params;
}