【问题标题】:ProxyPassReverse doesn't rewrite Location (http header)ProxyPassReverse 不重写位置(http 标头)
【发布时间】:2013-10-27 13:39:50
【问题描述】:

我在前端服务器 (server1) 中安装了一个 apache,它作为反向代理。我有另一台运行 web 应用程序的带有 tomcat 的服务器 (server2)。

我这样配置了我的反向代理(server1):

ProxyPass /app1/ ajp://server2:8009/app1/
ProxyPassReverse /app1/ https://www.external_domain_name.com/

当我连接到:

https://www.external_domain_name.com/app1/

我的网络应用程序运行正常。在某些页面中,网络应用程序将我 (302) 重定向到另一个页面。

然后,我被重定向到:

https://server1_internal_ip/app1/foo_bar

当我查看 http 标头时,响应标头包含:

Status code: 302
Location: https://server1_internal_ip/app1/foo_bar

所以,我的结论是 ProxyPass 工作正常,但 ProxyPassReverse 不是。

您能帮我了解一下出了什么问题吗?

谢谢

【问题讨论】:

    标签: reverse-proxy mod-proxy


    【解决方案1】:

    实际上 ProxyPassReverse 将替换您的服务器返回的位置。

    示例 1(仅 URL 路径)

    Apache2 设置

    ProxyPass "/8080" "http://localhost:8080"
    ProxyPassReverse "/8080/" "/"
    

    Node.js 设置

    const express = require("express");
    const app = express()
    
    app.get('/', (req, res) => {
        res.json({a: 8080})
    })
    
    app.get("/hi", (req, res) => {
        res.json({a: "8080hi"})
    })
    
    app.get("/redirect", (req, res) => {
        res.redirect("/hi")
    })
    
    app.listen(8080)
    

    原始位置是“位置:/hi”。
    新的是“位置:/8080/hi”。 (/ => /8080/)

    这意味着 Apache2 将 Location 值替换为 ProxyPassReverse 设置。
    或者您可以使用完整的 FQDN 来执行此操作。

    示例 2 (FQDN)

    Apache2 设置

    ProxyPass "/8080" "http://localhost:8080"
    ProxyPassReverse "/8080" "http://localhost:8080"
    

    Node.js 设置

    const express = require("express");
    const app = express()
    
    app.get('/', (req, res) => {
        res.json({a: 8080})
    })
    
    app.get("/hi", (req, res) => {
        res.json({a: "8080hi"})
    })
    
    app.get("/redirect", (req, res) => {
        res.setHeader("Location", "http://localhost:8080/hi")
        res.send(302)
    })
    
    app.listen(8080)
    

    Apache2 会将http://localhost:8080/hi 转换为http://localhost/8080/hi
    (如果我的 Apache2 配置为 80 端口。)

    【讨论】:

      【解决方案2】:

      改为设置它

      ProxyPassReverse /app1/ ajp://server2:8009/app1/
      

      当我遇到类似问题时,似乎对我有用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-07-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-02-06
        • 1970-01-01
        相关资源
        最近更新 更多