Docker – Apache container with Server-Status

dockerhttpd

Have someone here setup successfully apache with server status inside of a container to allow access from the host? I have already tried with –add-host param at docker to then allow that host at the config file but I still get the Forbidden Error Message

The httpd config file for server status is set as:

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from mainserver
</Location>

I'm creating the docker container with this command:
docker run -e 80:80 httpdimage /usr/sbin/httpd -DFOREGROUND

From the host, then I'm doing the test with this curl command:
curl http://localhost/server-status

And I get then the error message:

Forbidden

You don't have permission to access /server-status
on this server.

Best Answer

There are a few things that could be going on here.

First, from the perspective of your container, your host has the address of your docker0 bridge; this is the default route inside your container, so you can get it like this:

host_address=$(ip route | awk '$1 == "default" {print $3}')

You can have an ENTRYPOINT script or something substitute this into your Apache configuration when you start the container, giving you something like:

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from 172.47.42.1
</Location>

If you are running Apache 2.4, this won't work. In Apache 2.4, the Allow and Deny directives have been replaced with a newer syntax, so you actually need:

<Location /server-status>
    SetHandler server-status
    Require ip 172.17.42.1
</Location>

This is what finally worked on my system.