Tomcat behind Apache 2 reverse proxy
Today, I wanted to set up a Tomcat engine that runs on some 80xx port so that it looks like a usual web server running on port 80. I had to fiddle with the settings for some time and maybe, you have got the same steps to do, so this is what I did:
Insert this virtual host declaration in /etc/apache2/vhosts.d/myown_vhost.conf:
<VirtualHost *:80> ServerName www.myownhost.com ServerAdmin firstname.lastname@example.org # don't lose time with IP address lookups HostnameLookups Off # needed for named virtual hosts UseCanonicalName Off ProxyPass / http://localhost:80xx/ ProxyPassReverse / http://localhost:80xx/ </VirtualHost>
But this was not enough. Some application inside Tomcat calls
request.getServerName() and still gets
localhost. So, inside Tomcat, I had to edit
conf/server.xml and modify the connector declaration:
<Connector port="8088" address="localhost" proxyName="www.myownhost.com" proxyPort="80" ... other arguments here ...
After that, everything worked just fine.
For detailed information, see https://tomcat.apache.org/tomcat-9.0-doc/config/http.html