Select Page

Accessing a docker container behind apache’s reverse proxy bump into error:

Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /.

Reason: Error reading from remote server

Additionally, a 502 Bad Gateway error was encountered while trying to use an ErrorDocument to handle the request.

and logs reveals:

[proxy:error] [pid 3256] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:6001 (*) failed

Docker was listening on 127.0.0.1 as oppose to localhost and these two are not the same technically, apache translate http://localhost:PORT to a unix socket instead of TCP Scoket

Solution:

ProxyPass / http://localhost:6001/
ProxyPassReverse / http://localhost:6001/

RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*)           ws://localhost:6001/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*)           http://localhost:6001/$1 [P,L]

To:

ProxyPass / http://127.0.0.1:6001/
ProxyPassReverse / http://127.0.0.1:6001/

RewriteEngine On
RewriteCond %{HTTP:Upgrade} =websocket [NC]
RewriteRule /(.*)           ws://127.0.0.1:6001/$1 [P,L]
RewriteCond %{HTTP:Upgrade} !=websocket [NC]
RewriteRule /(.*)           http://127.0.0.1:6001/$1 [P,L]