繁体   English   中英

apache mod_proxy ProxyPassReverse位置标头

[英]apache mod_proxy ProxyPassReverse Location header

我在apache后面的tomcat具有以下设置:

ServerName someapp.com

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

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

Location: /someapp/foo

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

我做错了什么?

因为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)

不确定这是最好的方法,但是到目前为止,发现的唯一解决方法是使用mod标头:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM