【问题标题】:Nginx redirect with parts of URL带有部分 URL 的 Nginx 重定向
【发布时间】:2020-10-06 18:06:00
【问题描述】:

我在使用 nginx 时遇到了重定向问题,我真的不知道该怎么做。

问题是我需要将所有流量重定向到一个网站包括路径

BASE_URLhttps://example.com/auth/

例如,如果请求是:https://example.com/auth/some/path/

我需要它重定向到:https://newdomain.com/some/path/

也就是说,我需要将/some/path/的部分连接到新的URL。

这是我尝试过的部分代码

   location  /auth/* {
          proxy_pass https://newdomain.com/$request_uri; 
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_set_header Host $host;
   }

谢谢。

【问题讨论】:

    标签: nginx redirect nginx-reverse-proxy


    【解决方案1】:

    问题似乎是 URL 处理。你需要一个小的正则表达式并得到结果。

    尝试:

      location  ~ ^/auth/(.*)$  {
          proxy_pass https://newdomain.com/$1; 
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection "upgrade";
          proxy_set_header Host $host;
      }
    

    你可以在那里找到例子https://www.liaohuqiu.net/posts/nginx-proxy-pass/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-13
      • 2012-08-02
      • 2016-06-22
      • 1970-01-01
      • 2015-01-20
      • 2019-06-17
      相关资源
      最近更新 更多