apache mod_proxy ProxyPassReverse位置标头

问题描述 投票:0回答:2

我通过以下设置在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
2个回答
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用ProxyPassReverse设置替换了Location值。 或者您可以使用完整的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)

0
投票

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

Header edit Location ^/someapp/ http://someapp.com/
© www.soinside.com 2019 - 2024. All rights reserved.