我在前端服务器(server1)中安装了一个apache,它作为反向代理。我有一个运行webapp的tomcat的另一台服务器(server2)。
我配置了我的反向代理(server1):
ProxyPass /app1/ ajp://server2:8009/app1/
ProxyPassReverse /app1/ https://www.external_domain_name.com/
当我连接到:
https://www.external_domain_name.com/app1/
我的网络应用程序正常工作。在某些页面中,Web应用程序将我(302)重定向到另一个页面。
然后,我被重定向到:
https://server1_internal_ip/app1/foo_bar
当我查看http标头时,响应头包含:
Status code: 302
Location: https://server1_internal_ip/app1/foo_bar
所以,我的结论是ProxyPass正常工作,但ProxyPassReverse却没有。
你能帮我解释一下出了什么问题吗?
谢谢
将其设置为此
ProxyPassReverse /app1/ ajp://server2:8009/app1/
当我遇到类似的问题时,似乎为我工作。
实际上,ProxyPassReverse将替换服务器返回的位置。
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来执行此操作。
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端口。)