【问题标题】:nginx url rewrite with reverse proxy使用反向代理重写 nginx url
【发布时间】:2020-06-24 22:51:25
【问题描述】:

我目前在 nginx 上进行配置,如下所示 上游后端 {

least_conn;

server 172.17.0.4 max_fails=2 fail_timeout=30s;

server 172.17.0.2 max_fails=2 fail_timeout=30s weight=2;

}

服务器{

listen       80;

server_name example.com;



location / {

proxy_pass http://backend;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header Host $host;

}

}

我正在寻找类似的 url 重写

例如:如果有人访问 example.com/sample。我们要重定向到 proxy_pass backend/new/1/sample

但是当我执行 proxy_pass 时,它会重定向到,但浏览器中的 url 仍然显示为 example.com/sample

它应该显示 example.com/new/1/sample

如何重写 url 并在浏览器中显示 url。

提前谢谢你

【问题讨论】:

  • 您是否需要将您的请求 example.com/sample 代理到 backend/sample(您当前的配置)或 backend/new/1/sample

标签: nginx nginx-reverse-proxy


【解决方案1】:

我会说您需要 http 301 重定向。所以我会尝试这样的事情:

return 301 backend/new/1/sample;

【讨论】:

    猜你喜欢
    • 2014-02-01
    • 2020-12-18
    • 2014-03-24
    • 2018-07-01
    • 2018-01-31
    • 2012-12-11
    • 1970-01-01
    • 2021-09-10
    • 1970-01-01
    相关资源
    最近更新 更多