nginx - 如何配置 Nginx 以进行页面刷新/重新加载
问题描述
我在后端服务器上部署了两个耳朵文件。一个带有网络上下文根“/”,另一个带有“/bli”。我正在使用 Nginx 将请求传递给后端服务器。假设 xyz 是外部 url,它通过 nginx 将请求传递给后端服务器。
这就是正在发生的事情 - 1) https://xyz - 工作正常。页面刷新/重新加载也可以正常工作 2) https://xyz/bli - 重定向到 myserver.com/bli/ 并收到错误 3) https://xyz/bli/ - 工作正常但页面刷新/重新加载重定向到 myserver .com/bli/
myserver.com 在不可解析的 URL 中,所以我收到错误
我尝试包括以下指令 -
location /bli/{
proxy_pass https://backend;
proxy_set_header Host myserver.com;
}
这解决了重定向到 myserver.com 的问题。但它改为重定向到https://xyz:8011/bli/,这会给出错误。它将与https://xyz:443/bli/ 一起使用。不知道 8011 端口从哪里来的 URL。
我也试过这个,但它重定向到 nginx 上的索引文件-
location /{
try_files $uri $uri/index.html
}
我试过这个,但没有奏效-
location /{
try_files $uri $uri/bli /bli
}
这是我的conf文件
server {
listen *:8011;
root /apps/nginx/con/htdocs;
status_zone application_8011;
error_page 404 /error404.html;
error_page 500 502 503 504 /error500.html;
location /error404.html {
root /apps/nginx/con/htdocs/error_b;
}
location /error500.html {
root /apps/nginx/con/htdocs/error_b;
}
location / {
proxy_pass https://backend;
proxy_set_header Host myserver.com;
}
location /index.html {
root /apps/nginx/con/htdocs;
}
}
刷新https://xyz:/bli/会在末尾删除 / 并重定向到 myserver.com/bli/ 。有没有办法可以避免在刷新时删除 / 以便刷新https://xyz:/bli/。或者我需要在我的配置文件中包含什么来解决页面刷新问题。
解决方案
以下解决方案对我有用 -
location /{
proxy_pass https://backend;
proxy_set_header Host myserver.com;
port_in_redirect off
}
location /bli/{
proxy_pass https://backend/bli/;
proxy_set_header Host myserver.com;
port_in_redirect off
}
推荐阅读
- java - Spring Boot:如何获取部署在 JBoss(或任何应用服务器)上的应用程序的运行端口?
- ios - iOS 动画成功弹出窗口
- python-3.x - 如何在 mongoengine 中获取已更改文档的当前字段值?
- snakemake - Snakemake 无效语法
- angularjs - 在角度混合应用程序中首次成功路由后,Angular router.navigate 无法导航
- snowflake-cloud-data-platform - 雪花 - 加入拆分功能的结果
- html - Angular / HTML中的退出弹出窗口
- lua - 使用#来获取数组的长度不起作用
- c - 从 C 中的十六进制字符串创建字节数组
- python-3.x - pycharm和python解释器中的return语句有何不同?