[iyunv@www ~]# vim /etc/nginx/extra/nginx-vhost.conf
server {
listen *:80 default_server;
server_name www.stu31.com;
index index.html index.htm ;
root /www/vhosts/www1;
access_log /var/log/nginx/www.stu31.com.log main ;
location /status {
stub_status on;
allow 172.16.0.0/16;
deny all;
}
}
2..重启nginx
语法检查:
1
2
3
[iyunv@www ~]# service nginx configtest
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
重启nginx
1
2
3
4
5
[iyunv@www ~]# service nginx restart
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
3.访问status页面:
1
2
3
4
5
[iyunv@www ~]# curl http://172.16.31.40/status
Active connections: 1
server accepts handled requests
6 6 5
Reading: 0 Writing: 1 Waiting: 0
4.nginx status详解
1
2
3
4
5
active connections – 活跃的连接数量
server accepts handled requests — 总共处理了6个连接 , 成功创建6次握手, 总共处理了5个请求
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.
5.虚拟开启用户认证
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[iyunv@www ~]# vim /etc/nginx/extra/nginx-vhost.conf
server {
listen *:80 default_server;
server_name www.stu31.com;
index index.html index.htm ;
root /www/vhosts/www1;
access_log /var/log/nginx/www.stu31.com.log main ;
location /status {
stub_status on;
auth_basic "Nginx-status";
auth_basic_user_file /etc/nginx/.htpasswd;
allow 172.16.0.0/16;
deny all;
}
}
6.创建用户认证文件
1
2
3
4
5
6
[iyunv@www ~]# htpasswd -c -m /etc/nginx/.htpasswd status
New password:
Re-type new password:
Adding password for user status
[iyunv@www ~]# ll -a /etc/nginx/.htpasswd
-rw-r--r-- 1 root root 45 Dec 27 12:33 /etc/nginx/.htpasswd