When we do the apache proxy integration with the tomcat like in my another blog Apache and Tomcat Integration we use the localhost mapping in the httpd config for the tomcat url , the main reason behind this is securing the tomcat so that it is not able to accessable from the outside world or using the domain, every request for tomcat need to be pass away from the apache.
Now using this approach main problem that occur is tomcat doesn't aware about the domain name on which he is running, So when we want to redirect to another page from tomcat using response.sendRedirect() then it redirect the request using the localhost instead of domain name and link failure is occurred.
So Now how to handle this situation, In apache we have a feature to carry forward the domain name in the tomcat using the Proxy. for doing this you need to open the httpd.conf file located in /etc/httpd/conf/ and replace the following code snipped.
After adding this you need to restart apache and tomcat service once.
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
Now using this approach main problem that occur is tomcat doesn't aware about the domain name on which he is running, So when we want to redirect to another page from tomcat using response.sendRedirect() then it redirect the request using the localhost instead of domain name and link failure is occurred.
So Now how to handle this situation, In apache we have a feature to carry forward the domain name in the tomcat using the Proxy. for doing this you need to open the httpd.conf file located in /etc/httpd/conf/ and replace the following code snipped.
ServerName <DOMAIN_NAME>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
After adding this you need to restart apache and tomcat service once.
Comments
Post a Comment