我有一个别名的nginx设置,并试图用try_files做一个重写规则。 问题在于它预先提供了文档根目录而没有find该文件。 组态:
server { listen 80; server_name mysite.com; root /var/www/default; index index.html index.htm index.php; location /coolapp { alias /home/myhome/coolapp/www/; index index.php; try_files $uri $uri/ /home/myhome/coolapp/www/index.php?url=$uri&$args; location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $request_filename; } } }
并在nginx错误日志中:
[error] 21903#0: *2 open() "/var/www/default/home/myhome/coolapp/www/index.php" failed (2: No such file or directory) ...
为什么它预先在try_files中的根目录? 我想把别名视为自己的根。 我在这里做错了什么?
你使用alias ,你应该使用另一个root 。
root将指定的path添加到请求。
aliasreplace位置path指定的path部分。
你也遇到了一个bug ,但是一旦你把适当的configuration放在适当的位置,