情景描述
当我访问后台时,重定向后的目标URL应该是 “https://www.lanbenben.com/???/index.html”,可结果URL确为 “https://serverlist/???/index.html”
这个问题也是我在部署博客时发生的,接下来大家跟我一起往下看 👀
由于涉及部分隐私,所以贴了一张差不多原理的图 😆
解决方案
1.后端代码示例
@GetMapping("${xxx}")
public void admin(HttpServletResponse response) throws IOException {
String demoIndexRedirectUri =
DemoUtils.ensureBoth(demoProperties.getAdminPath(), DemoUtils.URL_SEPARATOR)
+ INDEX_REDIRECT_URI;
response.sendRedirect(demoIndexRedirectUri);
}
2.Nginx 原配置(核心部分)
server {
location / {
root html;
index index.html index.htm;
proxy_pass http://serverlist;
}
}
3.修改之后的 Nginx 配置(核心部分)
server {
location / {
root html;
index index.html index.htm;
proxy_pass http://serverlist;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
本文后续将会更新更详细的解决步骤,敬请期待
评论区