当我尝试浏览http://exmaple.dev.local/test.html 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 conf是:
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";
}
}
答案 0 :(得分:1)
不要在$1
指令中使用位置变量(root
)。定义命名变量。
server_name "~^(?<domain>.+)\.dev\.local$";
...
root /var/www/$domain/webroot/;
...
这是正则表达式位置中$1
变量重置为空字符串的问题。