|
|
错误信息:
在 nginx 的一个 vhost 配置中,在根目录放置 index.php 文件,并为子目录设置反代,直接访问域名时返回 nginx403,需手动添加 index.php 方可正常访问 php 。
猜测原因:
在使用 nginx 反代时,将反代设置为子目录,location 使用直接匹配。 而引入 php 配置时使用正则匹配。 直接匹配优先级高于正则匹配。
配置文件示例:
- server {
- listen 443 ssl http2;
- server_name domain_name;
- root /home/www;
- index index.php;
-
- #ssl 配置略去
-
- location ~ \.php$ {
- include fastcgi_params;
- fastcgi_intercept_errors on;
- fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
- fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
- }
- location /deluge/ {
- proxy_pass http://localhost:8112/;
- proxy_set_header X-Deluge-Base "/deluge/";
- add_header X-Frame-Options SAMEORIGIN;
- }
- }
复制代码
尝试解决:
将修改为强制匹配在 location 模块中使用 alias 指向绝对目录
- location = / {
- include fastcgi_params;
- fastcgi_intercept_errors on;
- fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
- fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
- index index.php
- alias /home/www;
- }
复制代码
访问网页,返回纯文本内容 File not found.
已知在不设置子目录反代时,该配置 php 可正常访问。
请问是否有办法解决这个问题? |
|