简体   繁体   English

apache mod_proxy ProxyPassReverse位置标头

[英]apache mod_proxy ProxyPassReverse Location header

I have tomcat behind apache with the following setup: 我在apache后面的tomcat具有以下设置:

ServerName someapp.com

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

Everything works fine until tomcat response header contains something like: 一切正常,直到tomcat响应标头包含以下内容:

Location: /someapp/foo

It causes 404 or 500 because the browser goes to " http://someapp.com/someapp/foo " instead of " http://someapp.com/foo/ " 由于浏览器转到“ http://someapp.com/someapp/foo ”而不是“ http://someapp.com/foo/ ”,因此会导致404或500

What i did wrong? 我做错了什么?

Because ProxyPassReverse will replace the Location which your server returned. 因为ProxyPassReverse将替换服务器返回的位置。
In your case, you can see example 1. 就您而言,您可以看到示例1。

Example 1 (Only URL Path) 示例1(仅URL路径)

Apache2 Setting Apache2设置

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

Node.js Setting 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)

Original Location is "Location: /hi". 原始位置是“位置:/ hi”。
New one is "Location: /8080/hi". 新的是“位置:/ 8080 / hi”。 (/ => /8080/) (/ => / 8080 /)

That means Apache2 replaced the Location value with ProxyPassReverse setting. 这意味着Apache2用ProxyPassReverse设置替换了Location值。
Or you can use full FQDN to do it. 或者,您可以使用完整的FQDN来执行此操作。

Example 2 (FQDN) 示例2(FQDN)

Apache2 Setting Apache2设置

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

Node.js Setting 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