All*_*lfo 10 alias location nginx
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;
}
}
Run Code Online (Sandbox Code Playgroud)
这种配置有效.但是,如果location /test/被替换,例如location /testpath/它不起作用(没有指定输入文件).我假设根据别名指令的解释,"位置"部分被删除,从而/testpath/info.php导致html/test/info.php.
谢谢你的任何建议.
All*_*lfo 11
server {
listen 80;
server_name pwta;
index index.html index.php;
root html;
location /testpath/ {
alias html/test/;
}
location ~ ^/testpath/(.+\.php)$ { ### This location block was the solution
alias html/test/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$1;
include fastcgi_params;
}
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;
}
Run Code Online (Sandbox Code Playgroud)
小智 9
无论是alias和root指令最好用绝对路径使用.您可以使用相对路径,但它们与prefix用于编译nginx 的配置选项相关,通常不是您想要的.
您可以通过执行nginx -V并查找以下值来查看此信息--prefix=.
通过查看日志证明这一点,你会发现"没有这样的文件"错误.