【问题标题】:apache mod_proxy ProxyPassReverse Location headerapache mod_proxy ProxyPassReverse 位置标头
【发布时间】:2016-05-11 21:06:02
【问题描述】:

我在 apache 后面有 tomcat,设置如下:

ServerName someapp.com

ProxyPass / http://localhost:8080/someapp/
ProxyPassReverse / http://localhost:8080/someapp/

一切正常,直到 tomcat 响应标头包含以下内容:

Location: /someapp/foo

它会导致 404 或 500,因为浏览器转到“http://someapp.com/someapp/foo”而不是“http://someapp.com/foo/

我做错了什么?

【问题讨论】:

    标签: apache http tomcat mod-proxy


    【解决方案1】:

    因为 ProxyPassReverse 将替换您的服务器返回的位置。
    在您的情况下,您可以查看示例 1。

    示例 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)
    

    【讨论】:

      【解决方案2】:

      不确定这是最好的方法,但现在找到了唯一的 mod header 修复:

      Header edit Location ^/someapp/ http://someapp.com/
      

      【讨论】:

        猜你喜欢
        • 2013-10-27
        • 2011-12-10
        • 2015-07-18
        • 2011-04-04
        • 1970-01-01
        • 2013-01-05
        • 2015-10-30
        • 2012-11-13
        • 1970-01-01
        相关资源
        最近更新 更多