
最新玩 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 错误
请大神帮助解惑
1 rrfeng 2017-09-21 18:26:49 +08:00 不要嵌套 location |
2 csbde OP 放外面一样的效果 |
3 csbde OP 也谢谢,铜币送上 |
4 paranoiagu 2017-09-21 18:37:12 +08:00 via Android 看看 access 日志,再找原因 |
5 csbde OP 日志就是 404 |
6 csbde OP 铜币送上 |
7 csbde OP 也送上感谢 |
8 0ZXYDDu796nVCFxq 2017-09-21 18:56:09 +08:00 via iPhone 正则的 location 下用 alias 要非常注意 建议不使用正则 具体参考官方文档吧 |
10 qcloud 2017-09-21 19:20:19 +08:00 via iPhone 鬼故事 |