server {
listen 80;
server_name pwta;
root html;
location /test/{
alias html/test/;
autoindex on;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
此配置有效。但是,如果location /test/
被替换,例如location /testpath/
它不起作用(没有指定输入文件)。我根据别名指令的解释假定“位置”部分被丢弃,因此/testpath/info.php
将导致html/test/info.php
。nginx别名+位置指令
感谢您的任何建议。
我不完全明白为什么这样做,但确实解决了问题。任何人都可以添加更多关于中间位置块的更多解释吗? – Brad 2013-12-04 20:33:57
添加'alias'将有效地覆盖'$ document_root'到任何别名。请注意,它不会影响'$ fastcgi_script_name'或'$ request_filename'。使用新的'$ document_root'和正则表达式匹配文件名,解析为脚本文件。 – Gajus 2015-03-27 16:55:50
注意,当请求位于'/ testpath /'下时,最后一个位置块没有做任何事情。 – Gajus 2015-03-27 17:02:20