动态根文件夹不适用于*.php nginx

动态根文件夹不适用于*.php nginx,php,nginx,configuration,Php,Nginx,Configuration,当我尝试浏览Nginx服务静态文件“test.html”时,但当我尝试index.php时,它并没有提供服务。 我做错了什么 错误是404未指定输入文件。日志说: test location: ~ "\.php$" using configuration "\.php$" http cl:-1 max:1048576 rewrite phase: 3 post rewrite phase: 4 generic phase: 5 generic phase: 6 generic phase: 7

当我尝试浏览Nginx服务静态文件“test.html”时,但当我尝试index.php时,它并没有提供服务。 我做错了什么

错误是404未指定输入文件。日志说:

test location: ~ "\.php$"
using configuration "\.php$"
http cl:-1 max:1048576
rewrite phase: 3
post rewrite phase: 4
generic phase: 5
generic phase: 6
generic phase: 7
access phase: 8
access phase: 9
post access phase: 10
try files phase: 11
http init upstream, client timer: 0
epoll add event: fd:13 op:3 ev:80000005
http script copy: "/var/www/"
http script capture: ""
http script copy: "/webroot/"
http script copy: "/var/www/"
http script capture: ""
http script copy: "/webroot/"
http script copy: "QUERY_STRING"
fastcgi param: "QUERY_STRING: "
http script copy: "REQUEST_METHOD"
http script var: "GET"
fastcgi param: "REQUEST_METHOD: GET"
http script copy: "CONTENT_TYPE"
fastcgi param: "CONTENT_TYPE: "
http script copy: "CONTENT_LENGTH"
fastcgi param: "CONTENT_LENGTH: "
http script copy: "/var/www/"
http script capture: ""
http script copy: "/webroot/"
http script copy: "SCRIPT_FILENAME"
http script var: "/var/www//webroot/"
fastcgi param: "SCRIPT_FILENAME: /var/www//webroot/"
http script copy: "SCRIPT_NAME"
http script var: "/index.php"
fastcgi param: "SCRIPT_NAME: /index.php"
我的nginx配置是:

server {
listen 80;
server_name "~^(.*)\.dev\.local$";

#if directory doesn't exist
if (!-d /var/www/$1/webroot/) {
    rewrite . http://dev.local redirect;
}
root /var/www/$1/webroot/;
index index.php index.html index.htm;

autoindex on; 
rewrite_log on;
open_file_cache off;

#cake beauty URLs
try_files $uri $uri/ /index.php;
location ~* \.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param ENVIRONMENT "bar";
}
}

不要在根指令中使用位置变量$1。定义命名变量

server_name "~^(?<domain>.+)\.dev\.local$";
...
root /var/www/$domain/webroot/;
...

这里是regex位置的问题,其中$1变量被重置为空字符串。

实际上不是。这就是nginx中变量的工作方式。它们在最后一刻被扩展。顺便说一句,如果碰巧有location ~*^/*\.php$,那么$1变量中会出现什么情况?这是真的。再次感谢你=