【问题标题】:How to configure Nginx for page refresh/reload如何配置 Nginx 以进行页面刷新/重新加载
【发布时间】:2019-07-24 14:30:01
【问题描述】:

我在后端服务器上部署了两个 ear 文件。一个带有网络上下文根“/”,另一个带有“/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
}

这是我的配置文件

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/。或者我需要在我的配置文件中包含什么来解决页面刷新问题。

【问题讨论】:

    标签: nginx nginx-config


    【解决方案1】:

    以下解决方案对我有用 -

    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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-13
      • 2016-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      相关资源
      最近更新 更多