[英]Apache rewrite or proxy with redirect of internal server
I am trying to use Apache as a proxy for an internal tomcat server, but the tomcat server performs a redirect that got me crazy 我正在尝试使用Apache作为内部tomcat服务器的代理,但是tomcat服务器执行的重定向使我发疯
I first tried mod_proxy through: 我首先尝试通过以下方式尝试mod_proxy :
ProxyPass / ajp://127.0.0.1:8045/bv-via-web/
ProxyPassReverse / ajp://127.0.0.1:8045/bv-via-web/
When accessing /
(root) the internal server performs a redirect to /bv-via-web/hola
which doesn't exist. 当访问
/
(根)时,内部服务器执行到/bv-via-web/hola
的重定向,该重定向不存在。 It should redirect to /hola
. 它应该重定向到
/hola
。 How can I achieve this through the Apache config? 如何通过Apache配置实现此目标?
As a workaround I though I add the following: 作为一种解决方法,我虽然添加了以下内容:
ProxyPass /bv-via-web/ ajp://127.0.0.1:8045/bv-via-web/
ProxyPassReverse /bv-via-web/ ajp://127.0.0.1:8045/bv-via-web/
But that doesn't work as it will extend the url to an internal request of bv-via-web/bv-via-web/hola
. 但这不起作用,因为它将URL扩展到内部请求
bv-via-web/bv-via-web/hola
。 So basically I want to change the url but don't know how that is possible with mod_proxy. 因此,基本上我想更改url,但不知道使用mod_proxy怎么可能。
I then tried mod_rewrite , with the following: 然后,我尝试使用以下命令mod_rewrite :
RewriteEngine on
RewriteRule ^/bv-via-web/(.*)$ http://127.0.0.1:8040/bv-via-web/$1 [P,L]
RewriteRule ^/(.*)$ http://127.0.0.1:8040/bv-via-web/$1 [P,L]
But then when I open the root of the website it performs a redirect and http://127.0.0.1:8040/bv-via-web/hola
appears in the browser address. 但是,当我打开网站的根目录时,它将执行重定向,并且浏览器地址中显示
http://127.0.0.1:8040/bv-via-web/hola
。
I don't understand, as it should work as an internal proxy due to the [P] flag. 我不明白,由于[P]标志,它应该作为内部代理工作。
What am I doing wrong ? 我究竟做错了什么 ?
I solved it by adding: 我通过添加解决了它:
ProxyPreserveHost On
Such it's not forwarded to the 127.0.0.1 as mentioned above. 如上所述,它不会转发到127.0.0.1。 So the total config snippet is:
因此,总的配置片段为:
RewriteEngine on
RewriteRule ^/bv-via-web/(.*)$ http://127.0.0.1:8040/bv-via-web/$1 [P]
RewriteRule ^/(.*)$ http://127.0.0.1:8040/bv-via-web/$1 [P]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.