这让我很紧张,因为它没有意义。我想定义一个别名规则,但 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目录),客户端:123.234.123.234,服务器:domain.com,请求:“GET/HTTP/1.1”,主机:“domain.com:666”
为什么它不读取完整路径?是否有像 not_ignore_last_letter
这样的指令我必须打开?
最佳答案
有一个long standing (try_files & alias) bug在 Nginx 中。
要解决此问题,您可以使用 root
指令再次设置或 fastcgi_param
中的 SCRIPT_FILENAME
和 SCRIPT_NAME
.
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
}
关于Nginx 别名忽略最后一个字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23921479/