AH01114: HTTP: failed to make connection to backend: localhost (apache as docker container)

45,569

Please refer https://docs.docker.com/network/network-tutorial-standalone/

It should be configured :

<VirtualHost *:80>
  ServerName localhost
  ProxyPass / http://172.17.0.1:8087
</VirtualHost>

or :

<VirtualHost *:80>
      ServerName localhost
      ProxyPass / http://ip_addressof_my-server-container:8087
</VirtualHost>

Use: docker inspect container_id to see ip address of container.

Share:
45,569
u123
Author by

u123

Updated on July 09, 2022

Comments

  • u123
    u123 5 months

    I am trying to setup apache in front of a server application (JIRA) on my local machine. Somewhat based on: https://mimiz.github.io/2017/05/18/Configure-docker-httpd-image.html

    Both apache and the server application are run as docker containers.

    Starting my server application works fine and I can access the web-ui at:

    http://localhost:8087
    

    But when I start apache and try to access it in my browser:

    http://localhost:80
    

    I get:

    Service Unavailable
    

    and when I look at the logs it says:

    H00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.18.0.5. Set the 'ServerName' directive globally to suppress this message
    [Mon Apr 01 09:08:50.408757 2019] [mpm_event:notice] [pid 1:tid 140140879032384] AH00489: Apache/2.4.38 (Unix) configured -- resuming normal operations
    [Mon Apr 01 09:08:50.409320 2019] [core:notice] [pid 1:tid 140140879032384] AH00094: Command line: 'httpd -D FOREGROUND'
    [Mon Apr 01 09:09:53.094495 2019] [proxy:error] [pid 8:tid 140140638869248] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8087 (localhost) failed
    [Mon Apr 01 09:09:53.094571 2019] [proxy_http:error] [pid 8:tid 140140638869248] [client 172.18.0.1:53110] AH01114: HTTP: failed to make connection to backend: localhost
    

    This is httpd.conf details I have enabled/added:

    LoadModule proxy_module modules/mod_proxy.so
    #LoadModule proxy_connect_module modules/mod_proxy_connect.so
    #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    ...
    <VirtualHost *:80>
      ServerName www.app1.lol
      ProxyPass / http://localhost:8087
    </VirtualHost>
    

    And this is how I start my server application:

    docker run --network sample-network -p 0.0.0.0:8087:8087 -ti -d --name my-server-container my-server-image
    

    And this is how I start apache:

    docker run -d -p 80:80 --network sample-network --name my-apache-container my-apache-image
    

    Is the problem my configuration in the httpd.conf file or in the docker run commands (or a combination of both)?

  • u123
    u123 over 3 years
    Where did you come up with 172.17.0.1 ?
  • Thanh Nguyen Van
    Thanh Nguyen Van over 3 years
    it's IP address of the gateway between the Docker host and the bridge network.
  • u123
    u123 over 3 years
    Ok will that always be that same value? And is that described in some docs somewhere?
  • Thanh Nguyen Van
    Thanh Nguyen Van over 3 years
    try it then let me know, document here docs.docker.com/network/network-tutorial-standalone , and I have gotten that issue before.
  • rmalchow over 1 year
    this should not be the accepted answer - the address of the container will change. in fact, the initial config is perfectly ok