Reputation: 1271
I am trying a very simple setup with "demo00" successfully working on Tomcat and accessible by public IP:Port/demo00. However when I try the virtual host below it fails to even find the website. The website can be pinged, I do not want to serve any static content just take every request to "demo00". Below is the Apache(2.4.54) virtual host second below is the Tomcat(9.0.64) configuration.
Apache
<VirtualHost *:80>
ServerName www.mydemo.com
ServerAlias mydemo.com
ProxyPass / ajp://localhost:8009/demo00 secret=123
ProxyPassReverse / ajp://localhost:8009/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Tomcat
<Connector protocol="AJP/1.3"
port="8009"
redirectPort="8443" address="::1" secretRequired="true" secret="123"
/>
Upvotes: 0
Views: 724
Reputation: 20882
The problem is probably the localhost
in httpd.conf plus the address="::1"
in Tomcat. I'll bet httpd is trying to use an IPv4 address but Tomcat is only listening with IPv6. Try address="localhost"
instead.
The configuration guide says that the default is to listen on all local interfaces. It does this by using "localhost"
as the default address. When using "localhost"
, the behavior depends upon the local DNS resolver. Some systems will return only 127.0.0.1
while others will return 127.0.0.1
and ::1
, and I'm not sure they will be returned in a predictable order (i.e. there is no DNS requirement that IPv4 precede IPv6 addresses in responses). Tomcat uses whatever Java returns from InetAddress.getByName(String host)
which doesn't specify which IP will be returned if the hostname maps to multiple IPs.
It is highly likely that using "localhost"
for both httpd and Tomcat will result in a connection which is reliable, since the DNS resolver is likely to be consistent if not predictable a priori. When in doubt, always use specific IP addresses in all places.
Incidentally, if you are building a new setup, I would highly recommend against using AJP. Instead, use mod_proxy_http and a plain-old HTTP(S) connector on the Tomcat side. You can read a presentation about why to migrate from AJP to HTTP on the Tomcat web site.
Upvotes: 2