首页 > 解决方案 > Nginx 保留代理导航回主机

问题描述

我设置了2页如下:

我想使用 nginx 从我的旧页面到新项目的下游

http://current-host/my-new-proj

http://new-host/my-new-proj

我尝试在当前主机上设置这样的 nginx 配置

server {
    listen       80;

    location / {
        root   html;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

    location /my-new-project {
        proxy_pass http://new-host/my-new-project;
    }

    location ^~ /_next/ {
        proxy_pass http://new-host/_next/;
    }


}

它似乎工作正常,但在新页面中我有一个链接可以导航到旧主页

<a href="http://current-host/"/>

但是,单击时不是导航到主页,而是导航到新项目的主页,当我刷新浏览器时,页面然后重新加载并显示正确的主页

我假设 nginx 正在检测请求的主机与当前主机相同,那么它只会触发应用内处理而不是导航。

无论如何我可以将此链接重定向到旧主机吗?

标签: nginxnginx-reverse-proxynginx-config

解决方案


推荐阅读