最新玩 nginx 配置,有一特殊需求,需要虚拟一个目录来运行根目录的程序。
nginx 配置如下,但出现了诡异现象,php 可以正常运行,各项参数也正确,但所有的静态页面不能正确读取。
root /home/wwwroot/wx.test.com/public/;
location ~ ^/my/
{
alias /home/wwwroot/wx.test.com/public/;
index index.html index.htm index.php default.html default.htm default.php;
add_header X-My yes;
autoindex off;
location ~ ^/my/(.+\.php)$
{
add_header X-subdir yes;
fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$1;
include fastcgi_params;
}
}
比如运行 www.test.com/my/index.php
是正确运行的。
任意静态文件放到 /home/wwwroot/wx.test.com/public/ 下面均无法读取到,报 404 错误 如静态文件的路径 /home/wwwroot/wx.test.com/public/index.html
访问路径:www.test.com/my/index.html 报 404 错误
请大神帮助解惑