11
<Location /status> SetHandler server-status order deny,allow allow from all </Location> 

But when I visit http://ip:port/status,

a 404 Not Found is reported, why?

5
  • Just for the heck of it, create an index.html file in that directory and see what happens. Commented Jul 19, 2011 at 5:02
  • @John Gardeniers,MUST that directory exist in the first place? I followed your advice but don't get anything different... Commented Jul 19, 2011 at 5:06
  • Obviously the directory must exist or you must always get a 404 for it because the server can't serve what isn't there. The reason I suggested creating the index file is because, depending on how your setup is configured, the lack of an index file may result in a 404 unless you specifically specify another file that does exist in your URL. Commented Jul 19, 2011 at 5:11
  • 1
    @John: For a server-status? I've never had to have a physical file on disk for server-status to work. Commented Jul 19, 2011 at 5:34
  • 2
    @John Gardeniers,why is the file still required when it's handled by SetHandler server-status? Commented Jul 19, 2011 at 5:35

7 Answers 7

23

This can also happen when you have a .htaccess file in the document root and that file contains a RewriteRule, as is common with CMS pretty URLs.

The explanation for this behaviour is as follows. The <Location> directives act first, but the handler is not called at this stage. So then the RewriteRule sets a handler, eg to run a PHP script, so SetHandler has no effect in the end.

If this is the cause, find the RewriteRule that is causing the problem(*), and add before it:

RewriteCond %{REQUEST_URI} !=/server-status 

This excludes the server-status URI from the RewriteRule in the same way that existing static files may be excluded. Of course what you use in place of /server-status must exactly match the Location chosen, which in the question is instead /status. (Tested on Apache 2.2.22 and Apache 2.4)

Addendum: also note that you can get a 403 trying to read the server-status if the DocumentRoot is not readable by the apache process at all, again because the server-status handler doesn't have a chance to work.

Addendum 2: if the .htaccess for the Apache default site is frequently overwritten, and the /server-status URL is necessary for eg Munin to work, then creating a <VirtualHost 127.0.0.1:80> stanza including the server-status handler may be administratively simplest.

Addendum 3(*): the RewriteRule that is causing the problem is potentially anything that matches the string /server-status. This may be identifiable because the first parameter will match anything, for example beginning RewriteRule . where the . will match any character, or ^(.*), or otherwise is catching the URI such as .*\bstatus$. You may also identify it because it deliberately excludes existing files with !-f.

For example, if WordPress is the main site and you want /server-status to appear on it, and for some reason Addendum 2 above is not applicable, you may want to insert an extra RewriteCond as follows:

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/server-status RewriteRule . /index.php [L] 

However, it probably does no harm before any RewriteRule.

6
  • It worked on Apache/2.4.6 (CentOS7). Commented Nov 22, 2016 at 9:45
  • 1
    It was the case on my Apache 2.4.10 on Debian too. THANKS! Commented Jun 2, 2017 at 9:08
  • The Apache documents stipulate that you need to have a RewriteEngine on directive for each virtual host in which you wish to use rewrite rules. I think this means I would need to configure the above RewriteCond once for each RewriteRule. So I chose to create a <VirtualHost 127.0.0.1> as suggested in Addendum 2 above to deal with multiple RewriteRules. And it seems to be working! Commented May 23, 2019 at 21:52
  • @CODE-REaD The mention of RewriteEngine is a red herring. It must already be on for the rule to be interfering with /server-status. I didn't say how to identify the rule "that is causing the problem" though, and maybe I should have, to save adding the line for each rule: the rule is probably a generic one where the first parameter is . or .* and may be preceded by other RewriteCond directives such as excluding a file !-f. Commented Aug 30, 2019 at 22:21
  • Also, on wordpress, it might be needed to remove write permissions from .htaccess file as wordpress keeps updating it with original content. Commented Jan 29, 2024 at 21:39
4

My guess would be that you didn't load the status module - Can you confirm it ?

1
  • This is the correct answer. Worked perfectly. Thanks. Commented May 13, 2016 at 21:25
3

Because you've misconfigured something. What do your logs say about the cause of the 404? My first guess would be that ip:port isn't a valid vhost (or at least not valid for the vhost you've put the <Location /status> in, anyway), and it's probably dropping back to the default vhost. The error logs will make mention of irrational paths you didn't configure if that's the case. Other error log messages will mean different things, which is why it's so important to check them.

4
  • The log also says File does not exist Commented Jul 19, 2011 at 4:37
  • 2
    Of course it does, that's why you got a 404. But what else does it say? Commented Jul 19, 2011 at 4:38
  • It doesn't say anything else. Commented Jul 19, 2011 at 4:53
  • 3
    At the very least, it will tell you which file does not exist. Commented Jul 19, 2011 at 5:33
2

https://serverfault.com/a/388457/ had the answer for me. Needed to actively block the call rather than trying to find/block every .htaccess RewriteRule interfering with request handling.

I added:

RewriteRule ^/server-status - [L]

Into the location block, and it started working.

0
  • you do not need to configure a directory or path or index file
  • are you trying a different port? you shouldn't be port 80

the docs are:

<Location /server-status> SetHandler server-status Order Deny,Allow Deny from all </Locaton> 

your location differs, I would not think it should matter, but try your location as /server-status instead of just /status.

However - I think Spud is right. you have not loaded that module.

-sean

0

If you are using WampServer, as I am for development, make a note of the following:

  • The httpd-info.conf file located at wamp\bin\apache\apache[version]\conf\extra contains relevant <Location> configuration:

    <Location /server-status> SetHandler server-status #Require host .example.com #Require ip 127 </Location>

  • This file may or may not actually be included in your Apache configuration. Look for the following line in your httpd.conf file and make sure it is uncommented:

    Include conf/extra/httpd-info.conf

In my case, the main problem was the latter: the line was commented by default and thus httpd-info.conf wasn't even loading.

-1

If you are using mod_rewrite and vhost configuration you need to add a blank vhost entry at the top of the vhost configuration file e.g.

<VirtualHost *:80> </VirtualHost> 

Then you can access it via the server IP address e.g. ip_address/server-status

1
  • Won't you also need a SetHandler server-status in that vhost? Commented Oct 9, 2013 at 12:07

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.