【问题标题】:rewrite url but show original url + nginx重写 url 但显示原始 url + nginx
【发布时间】:2017-09-02 20:05:56
【问题描述】:

我是 nginx 新手。 我正在尝试使用 nginx 将某个页面(“example.com/randomText/abc”)重定向到页面(“example.com/abc”)。

location ~ ^/(.*/abc){

#method 1
rewrite (.*) /abc break;

#method 2
#return 301 http://$host/abc;

#method 3
#proxy_pass http://$host/abc/;
#proxy_set_header Host $host;
#proxy_set_header X-Rewrite-URL $request_uri;
}

方法 1 和 2 正在工作,但它也将 url 更改为“http://example.com/abc” 方法 3 返回 502 错误。

【问题讨论】:

    标签: nginx nginx-location nginx-reverse-proxy


    【解决方案1】:

    你需要的是下面的东西

    location ~ ^/[^/]+/abc {
       proxy_pass http://$host/abc;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-04-10
      • 2011-04-28
      • 2019-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多