anqing
1
配置代理
**location /New/** {
proxy_pass http://127.0.0.1:8080/; # 注意结尾这个 /
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $server_name;
proxy_redirect off;
}
# 处理 /New(无斜杠)自动补斜杠,避免 404 或路径计算异常
location = /New {
return 301 /New/;
}
# 1. 精确匹配 /index/user/register.html
location = /index/user/register.html {
proxy_pass http://127.0.0.1:8080/Register/index;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
# 2. 可选:把 /index/user/register 301 到带 .html 的地址,避免 404
location = /index/user/register {
return 301 /index/user/register.html;
}
# 1. 精确匹配 /index/user/login.html
location = /index/user/login.html {
proxy_pass http://127.0.0.1:8080/Account/index;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
# 2. 可选:把 /index/user/login 301 到带 .html 的地址,避免 404
location = /index/user/login {
return 301 /index/user/login.html;
}
2 Likes
anqing
4
找到一个更完善的方法 可以将资源文件也通过代理访问
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
include /www/server/panel/vhost/rewrite/ask.fpf.com.conf;
location ^~ /New/ { # 匹配所有文件
proxy_pass http://127.0.0.1:8080/; # 注意结尾这个 /
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# 处理 /New(无斜杠)自动补斜杠,避免 404 或路径计算异常
location = /New {
return 301 /New/;
}
# 1. 精确匹配 /index/user/register.html
location = /index/user/register.html {
proxy_pass http://127.0.0.1:8080/Register/index;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
# 2. 可选:把 /index/user/register 301 到带 .html 的地址,避免 404
location = /index/user/register {
return 301 /index/user/register.html;
}
# 1. 精确匹配 /index/user/login.html
location = /index/user/login.html {
proxy_pass http://127.0.0.1:8080/Account/index;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
# 2. 可选:把 /index/user/login 301 到带 .html 的地址,避免 404
location = /index/user/login {
return 301 /index/user/login.html;
}
#禁止访问的文件或目录
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
1 Like