I am running an Apache Tomcat and Apache HTTP using Docker in an Ubuntu VM on my Windows machine. I have configured my HTTP server (running on port 80) to reverse proxy requests to the Tomcat (running on port 8080).
/etc/hosts:
127.0.0.1 localapp.com localhost
HTTP /conf/httpd.conf
<IfModule mod_proxy.c>
ProxyRequests Off
ProxyPass /app/api/ http://localapp.com:8080/api/
ProxyPassReverse /app/api/ http://localapp.com:8080/api/
</IfModule>
HTTP /conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache2/htdocs/app"
ServerName localapp.com
<Directory "/usr/local/apache2/htdocs/app">
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/usr/local/apache2/htdocs"
ServerName localhost
<Directory "/usr/local/apache2/htdocs">
Require all granted
</Directory>
</VirtualHost>
When I run the HTTP application, or try to hit localapp.com/api directory, I get a 502 response that DNS lookup failed.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Proxy Error</title>
</head><body>
<h1>Proxy Error</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
The proxy server could not handle the request <em><a href="/api">GET /api</a></em>.<p>
Reason: <strong>DNS lookup failure for: localapp.com</strong></p></p>
</body></html>
It seems like Apache HTTP for whatever reason can't proxy itself to localapp.com. The Tomcat application will work if I hit localapp.com:8080/api directly from the browser, so it seems like just an issue of the Apache HTTP server not resolving the DNS correctly.
For reference, my nsswitch.conf is:
passwd: compat
group: compat
shadow: compat
gshadow: files
hosts: files dns
networks: files
protocols: db files
services: db files
ethers: db files
rpc: db files
netgroup: nis
bridge
network you need to--link
them together for the name resolution to work. Upon creation, dockers strips all127.0.0.1
entries from the host's/etc/hosts
file so that won't work either. – Tommiie Aug 30 '18 at 18:21docker run -d --name httpd_container -p 80:80 --restart=always httpd_image
docker run -d --name tomcat_container -p 8080:8080 --restart=always tomcat_image
– Gavin Aug 30 '18 at 18:27