Apache ignores location directive

apache-2.2

I've uncommented the default section:

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

then restarted apache ('Syntax OK')

When I run links http://127.0.0.1/server-status I see 404 eror page.

# apachectl -S
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
_default_:443          site.com (/etc/httpd/conf.d/ssl.conf:74)
*:80                   is a NameVirtualHost
         default server site.com (/etc/httpd/sites-enabled/www.site.com.conf:1)
         port 80 namevhost site.com (/etc/httpd/sites-enabled/www.site.com.conf:1)
                 alias www.site.com
Syntax OK

Also I tried to insert the 'Location' block into <VirtualHost> and use the domain name instead of 127.0.0.1 but no luck.

I checked I'm at the proper config file by entering incorrect directive intentionally, that's the correct file.

What am I doing wrong?

Best Answer

I had the same problem, and it looks like the cause was similar: my application had an .htaccess file with the following:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ index.php [NC,L]

This took precedence over the Location section. It's rewriting all URLs that don't point to an actual file, and this includes server-status. By adding another RewriteCond before the RewriteRule, I was able to fix it:

RewriteCond %{REQUEST_URI} !=/server-status

Another approach is to add an Alias that maps your server-status URL to a different directory, one that doesn't use the .htaccess file. It seems like this can even be a directory that doesn't exist:

Alias /server-status /tmp/dummy

When updating from httpd 2.2 to 2.4, I also had to grant access to this dummy directory:

<Directory /tmp/dummy>
    Require all granted
</Directory>