2

I'm trying to enable the Nginx status page on my Centos 7 server.

I installed Nginx from the EPEL repository, Nginx is built with staus page support:

[root@server ~]# nginx -V 2>&1 | grep -o with-http_stub_status_module
with-http_stub_status_module

I have added a single config file /etc/nginx/conf.d/status.conf:

server {
    listen 80;
    server_name localhost;

    location /nginx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }
}

After restart, Nginx can't find the status page:

[root@server ~]# wget http://localhost/nginx_status
--2017-01-06 17:02:09--  http://localhost/nginx_status
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-01-06 17:02:09 ERROR 404: Not Found.

Every tutorial or example I found online says these are the steps I should take. Why do I keep getting a 404?

4

Your server block is missing a listen directive:

    listen [::]:80;

This directive tells nginx to answer IPv6 connections for that server. Unfortunately you omitted it, and only are answering IPv4 connections.

But, since localhost resolves to an IPv6 address (and in fact, IPv6 is the default protocol for everything on the Internet) your request is being processed by the default server block included with the default configuration, which is listening on IPv6.

You should be extra careful to ensure that all server blocks listen on IPv6 (mandatory, even if you do not have global IPv6 yet) and IPv4 (optional, only if you use IPv4).

3
  • Now, my 404 has changed to 403, one step at a time ;) – verhage Jan 6 '17 at 18:18
  • @verhage You didn't allow ::1; either :) – Michael Hampton Jan 6 '17 at 18:18
  • Haha, you beat me to it, I just added allow ::1; to my config and it works. I get it now, I didn't realize I had to also configure the IPv6 adresses. – verhage Jan 6 '17 at 18:20
3

I can't see any issues with your config and it's 404 rather than 403 which implies that it's not even read that config, so the debug steps I would go through are:

  • have you restarted nginx ;)
  • anything in the error_log?
  • is nginx really listening on localhost? on ip4 and ip6? (netstat -plnt)
  • try wget with the headers showing (wget -SO- http://localhost/nginx_status) perhaps something will show up
  • is nginx really reading this config file? (is there another somewhere? make a deliberate typo and see if it barfs)
  • is there more than one nginx? (getting stretched here, but stranger things have happened). Perhaps a restart isn't killing the old process?
  • remove the server_name directive and try without it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.