【问题标题】:Nginx proxy rewrite configurationNginx 代理重写配置
【发布时间】:2014-03-12 09:47:32
【问题描述】:

是否可以重写一个url并使用代理服务器进行后台连接?

举个例子,我想在我的代理服务器上使用这个 URL my.domain.org/demo,然后用 proxy_pass my.tomcat.local 将它重定向到另一个服务器上我的 tomcat 的根目录。

网址必须是my.domain.org/demo,并且必须使用代理网址my.tomcat.local(没有任何子域)。 这个钩子可以吗?

谢谢!!!!

【问题讨论】:

    标签: redirect nginx proxy rewrite


    【解决方案1】:

    是的,这是绝对可能的。

    使用如下配置

    location /demo {
        proxy_pass http://my.tomcat.local/; #Pay attention to the trailing slash. It MUST be present here.
    }
    

    重点是,如果指定的proxy_pass目的地包含路径(单斜杠也被认为是路径),那么Nginx会直接向那个URL传递请求;否则,Nginx 会将接收到的 URL 的路径附加到 proxy_pass 目标并使用生成的 URL。

    参考:http://wiki.nginx.org/HttpProxyModule#proxy_pass

    【讨论】:

    • 谢谢,有了这个配置就可以了。我之前已经用上游配置了这个,像这样......upstream demo { server 172.16.14.37:8081 fail_timeout=0; } location /demo { proxy_pass http://demo; } ......但这不起作用。为什么?
    猜你喜欢
    • 2019-11-11
    • 2020-12-18
    • 2016-07-04
    • 1970-01-01
    • 2015-03-10
    • 2020-07-05
    • 2013-11-29
    • 2013-04-23
    • 2015-04-03
    相关资源
    最近更新 更多