Nginx status page not found

verhage asked:

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:

[[email protected] ~]# nginx -V 2>&1 | grep -o 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;
        deny all;

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

[[email protected] ~]# wget http://localhost/nginx_status
--2017-01-06 17:02:09--  http://localhost/nginx_status
Resolving localhost (localhost)... ::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?

My answer:

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).

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.