未findNginx状态页面

我试图启用我的Centos 7服务器上的Nginx状态页面。

我从EPEL存储库中安装了Nginx,Nginx使用了staus页面支持:

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

我已经添加了一个configuration文件/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; } } 

重启后,Nginx无法find状态页面:

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

我在网上find的每一个教程或例子都说这是我应该采取的步骤。 为什么我一直得到404?

您的server块缺lesslisten指令:

  listen [::]:80; 

该指令告诉nginx回答该server IPv6连接。 不幸的是,你忽略了它,只能回答IPv4连接。

但是,由于localhostparsing为IPv6地址(事实上,IPv6是互联网上所有内容的默认协议),您的请求正在由缺省configuration(包含在IPv6上 listen的默认server块处理。

您应该特别小心,以确保所有server块在IPv6上listen (即使您还没有全局IPv6,也是强制性的)和IPv4(只有在使用IPv4时才是可选的)。

我看不到你的configuration有任何问题,它是404而不是403,这意味着它甚至没有读取configuration,所以我要经过的debugging步骤是:

  • 你重新启动nginx;)
  • 任何在error_log?
  • nginx真的在本地主机上监听吗? 在ip4和ip6上? ( netstat -plnt
  • 尝试使用wget显示标题( wget -SO- http://localhost/nginx_status ),可能会显示一些东西
  • nginx真的在读这个configuration文件吗? (是否有另一个地方?做一个故意的错字,看看它是否barf)
  • 有多个nginx吗? (在这里拉伸,但发生了陌生的事情)。 也许重启不是在杀死旧的进程?
  • 删除server_name指令并尝试没有它