这让我感到紧张,因为它没有意义。我想定义一个别名规则,但Nginx忽略了最后一个字母,并因某种原因尝试提供错误的文件。
配置:
server {
server_name domain.com;
listen 666;
root /srv/http;
autoindex on;
location /subdir {
alias /srv/http/someplace;
index index.php;
try_files $uri $uri/ /index.php?$args;
}
}
但我得到的错误是2014/05/28 17:46:25 [error] 13937#0: *221 opendir() "/srv/http/someplac" failed (2: No such file or directory), client: 123.234.123.234, server: domain.com, request: "GET / HTTP/1.1", host: "domain.com:666"
为什么不读完整条道路?是否有像not_ignore_last_letter
这样的指令我必须打开?
答案 0 :(得分:1)
Nginx中有long standing (try_files & alias) bug。
要解决此问题,您可以使用root
指令重新设置,或SCRIPT_FILENAME
中的SCRIPT_NAME
和fastcgi_param
。
root
指令示例
location /subdir {
root /srv/http/someplace;
index index.php;
try_files $uri $uri/ /index.php?$args;
# the usual stuff
}
自定义$document_root
& $fastcgi_script_name
示例
location ~ ^/subdir /(.*)$ {
set $custom_script_name "/subdir/index.php";
set $custom_document_root "/srv/http/someplace";
set $custom_bootstrap_script "/index.php";
try_files "" @customphp;
}
location @customphp {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $custom_document_root$custom_bootstrap_script;
fastcgi_param SCRIPT_NAME $custom_script_name;
# the usual stuff
}
答案 1 :(得分:0)
您不需要为您的php脚本路径添加别名!你可能需要使用fastcgi添加这样的东西:
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
}