CentOS 7 httpd /server-status limitations

apache-2.2centoscentos7muninvirtualhost

I have got VPS (using CentOS 7 as my OS) and now I am configuring Munin (monitoring software). I ran into a little problem with Apache monitoring.

Now I have got this cfg in my httpd.conf and everything works fine:

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

Terminal munin:

munin-node-configure --suggest | grep apache
apache_accesses            | yes  | yes                                    
apache_processes           | yes  | yes                                    
apache_volume              | yes  | yes 

But with this settings is /server-status available via all domain in the server:

example.com/server-status
example.net/server-status
192.0.2.1/example-status

I want to achieve something like this:

example.com/server-status  ---> ERROR 404
example.net/server-status ---> ERROR 404
192.0.2.1/example-status     ---> OK

So when I move the cfg from httpd.conf to my vhost default file, which now looks:

<VirtualHost _default_:80>
    DocumentRoot /var/www/server
    ErrorLog /var/log/www/server_error.log
    CustomLog /var/log/www/server_requests.log combined
</VirtualHost>

And after update:

<VirtualHost _default_:80>
    DocumentRoot /var/www/server
    ErrorLog /var/log/www/server_error.log
    CustomLog /var/log/www/server_requests.log combined

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

Munin then stop monitor the apache service and will say:

apache_accesses            | yes  | no [apache server-status not found. check if mod_status is enabled]
apache_processes           | yes  | no [apache server-status not found. check if mod_status is enabled]
apache_volume              | yes  | no [apache server-status not found. check if mod_status is enabled]

PS: server dont have host name (I mean domain), I am using server IP as his hostname now

Can you help me achieve the required setting?

Best Answer

I think you could get away with creating a vhost with the ServerName you want. The ServerName in a named-based virtual host setup maps to whatever your browser/HTTP client puts into the Host header field.

So this should work:

<VirtualHost *:80>
    ServerName 192.168.1.2
    DocumentRoot /var/www/server
    ErrorLog /var/log/www/server_error.log
    CustomLog /var/log/www/server_requests.log combined

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

The Apache docs (https://httpd.apache.org/docs/current/mod/core.html#servername) specify you can use an IP as ServerName, and explain how ServerName works as follows:

If you are using name-based virtual hosts, the ServerName inside a section specifies what hostname must appear in the request's Host: header to match this virtual host.