重新编译安装nginx
cd /opt/nginx-1.8.0 ./configure --with-http_stub_status_module echo $? make echo $? make install echo $?
2.查看已安装的Nginx是否包含stub_status模块
[root@openvpn nginx-1.8.0]# /usr/local/nginx/sbin/nginx -V nginx version: nginx/1.8.0 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) configure arguments: --with-http_stub_status_module
3.在已有的nginx配置文件(/usr/local/nginx/conf/nginx.conf)里增加以下内容
server { listen 8080; server_name localhost; root html; index index.html; access_log off; location /nginx_status { stub_status on; } }
以上内容就在http标签里即可,要和其它server标签独立分开。
4.语法检查
[root@openvpn conf]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
5.优雅重启已经不起作用,直接停止服务再启动
[root@openvpn conf]# /usr/local/nginx/sbin/nginx -s stop [root@openvpn conf]# ps -ef|grep nginx root 4912 22321 0 15:12 pts/1 00:00:00 grep --color=auto nginx nginx 5722 1 0 Aug25 ? 00:00:00 /usr/bin/perl /data/local/nginx/perl-fcgi.pl -l /data/local/nginx/logs/perl-fcgi.log -pid /data/local/nginx/logs/perl-fcgi.pid -S /data/local/nginx/logs/perl-fcgi.sock [root@openvpn conf]# /usr/local/nginx/sbin/nginx [root@openvpn conf]# ps -ef|grep nginx root 4923 1 0 15:12 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx nobody 4924 4923 0 15:12 ? 00:00:00 nginx: worker process root 4931 22321 0 15:12 pts/1 00:00:00 grep --color=auto nginx nginx 5722 1 0 Aug25 ? 00:00:00 /usr/bin/perl /data/local/nginx/perl-fcgi.pl -l /data/local/nginx/logs/perl-fcgi.log -pid /data/local/nginx/logs/perl-fcgi.pid -S /data/local/nginx/logs/perl-fcgi.sock
6.端口已经打开
[root@openvpn conf]# netstat -lntup|grep 8080 tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 4923/nginx: master
7.执行结果成功
[root@openvpn conf]# curl xx.xxx.xx.xxx:8080/nginx_status Active connections: 1 server accepts handled requests 45 45 6 Reading: 0 Writing: 1 Waiting: 0
参考资料:http://xiaoluoge.blog.51cto.com/9141967/1642194