背景说明
server
{
...
#Directory protection rules, do not manually delete
include /www/server/panel/vhost/nginx/dir_auth/abc.com/*.conf;
# 这个是加密访问配置规则
...
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/abc.com.conf;
#REWRITE-END
# 这个是伪静态规则
...
}
location ~* ^/* {
#AUTH_START
auth_basic "Authorization";
auth_basic_user_file /www/server/pass/abc.com/root.pass;
include enable-php-72.conf;
#AUTH_END
}
location / {
if (!-e $request_filename){
rewrite ^/index.php(.*)$ /index.php?p=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
}
}
- 理论上 Nginx 配置文件读取是从上到下的,所以理论上将伪静态规则放在加密访问规则前面,即可
- 但是实践中不生效
- 加密规则的匹配优先级比伪静态规则高
解决方法
server
{
...
#Directory protection rules, do not manually delete
#include /www/server/panel/vhost/nginx/dir_auth/abc.com/*.conf;
# 这个是加密访问配置规则 注释掉 把内容写到下面的伪静态规则里面
...
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/abc.com.conf;
#REWRITE-END
# 这个是伪静态规则
...
}
location / {
#AUTH_START
auth_basic "Authorization";
auth_basic_user_file /www/server/pass/abc.com/root.pass;
include enable-php-72.conf;
#AUTH_END
if (!-e $request_filename){
rewrite ^/index.php(.*)$ /index.php?p=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
}
}
本文链接:
https://www.antixu.com/archives/436/