0

I have the most basic Apache proxy setup ever which I can't get to work.

On a CentOS server I'm running a regular Apache/httpd setup which serves a few websites. Apache listens on port 80 and 443.

I have been asked to set up an additional website but this one is packaged as a Docker Compose LAMP app which also uses Apache, internally.

Should be easy, right? All I have to do is use the external Apache to proxy incoming traffic from port 80 to whatever port is exposed by Docker (e.g. 8080):

[Internet] -> External Apache (:80) -> ProxyPass -> Docker (:8080) -> Internal Apache (:80) -> [Content]

But no matter what I do, it's just not working. I've got the external Apache proxy listening on port 80 just fine, and I can see incoming requests to it. But the proxied requests just can't reach the server exposed by Docker.

The error I see in the external Apache log is:

[proxy_http:error] [pid 11669] (70007)The timeout specified has expired: [client xxx:59517] AH01102: error reading status line from remote server localhost:8080

There is nothing in the internal Docker Apache log.

Note: I tried temporarily stopping my external Apache instance and allowing the Docker stack to expose itself directly to the server using ports: 80:80, and it was reachable - so I know the Docker stack works. It's something to do with the port mapping and/or proxy that causes the problem.

The strange thing is, I know Docker is exposing the port correctly because it responds when probed:

# nc -zv localhost 8080
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to 127.0.0.1:8080.
Ncat: 0 bytes sent, 0 bytes received in 0.01 seconds.

I guess this eliminates the firewall as a cause as well because if it was firewalled I'd expect Ncat to get rejected.

Here's what my docker-compose.yml file looks like:

# docker-compose.yml
version: '3'

services:
  php:
    image: php:7.2-apache
    ports:
      - 8080:80
    volumes:
      - ./html:/var/www/html # Contains index.php

Here's the external Apache proxy conf file:

# apache2 running outside of Docker
# test.local-vhost.conf
LoadModule proxy_module      modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

<VirtualHost *:80>

    ServerName example.com

    ProxyPreserveHost On
    ProxyPass         / http://localhost:8080
    ProxyPassReverse  / http://localhost:8080

</VirtualHost>
1
  • I have reproduced your scenario in a test environment (debian) and it works. Is it possible that the port 8080 is used by other process in the host machine? 2 hours ago

0

You must log in to answer this question.

Browse other questions tagged .