Sending redirect in Tomcat web application behind a Apache 2 proxy (mod_proxy)

前端 未结 5 698
攒了一身酷
攒了一身酷 2021-01-01 18:20

I have a web application on tomcat http://localhost:8080/WebApp/

The I have configrued Apache 2 (mod_proy) so that the web application is directly acces

5条回答
  •  时光取名叫无心
    2021-01-01 18:59

    I also had this problem and spent some time on it. I believe that if you change your apache httpd configuration to the following your redirect will work:

    
        ProxyPreserveHost On
    
        ProxyPass / http://localhost:8080/WebApp/
        ProxyPassReverse / http://localhost/WebApp/
    
        ProxyPassReverseCookiePath /WebApp /
    
    

    This is because the tomcat response headers will contain the proxy headers (i.e. the Location header is http://localhost/WebApp rather than http://localhost:8080/WebApp) because ProxyPreserveHost is switched On.

    As a footnote: This also works with you want to change your webapps context. Say you wanted to change the publicly visible context to context you can use the following:

    
        ProxyPreserveHost On
    
        ProxyPass /context/ http://localhost:8080/WebApp/
        ProxyPassReverse /context/ http://localhost/WebApp/
    
        ProxyPassReverseCookiePath /WebApp /context
    
    

    For reference, I found this blog post extremely helpful: Reverse Proxying Tomcat Web Applications Behind Apache

提交回复
热议问题