码迷,mamicode.com
首页 > 其他好文 > 详细

nginx版本隐藏以及访问状态

时间:2015-12-20 09:20:53      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:nginx隐藏版本号 nginx访问状态

1:nginx版本隐藏之前访问

root@zxl-nginx conf]# curl -I http://www.zxl.com
HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Sat, 19 Dec 2015 14:07:29 GMT
Content-Type: text/html
Content-Length: 44
Last-Modified: Fri, 18 Dec 2015 05:23:18 GMT
Connection: keep-alive
ETag: "56739846-2c"
Accept-Ranges: bytes

2:修改nginx配置文件,只需在http段中加入server_tokens off;即可

http {
    .......//省略
    server_tokens        off;
    .......//省略
include ./conf.d/*.conf;
}

3:检查nginx配置文件以及重新加载

[root@zxl-nginx conf]# 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
[root@zxl-nginx conf]# nginx -s reload


再次访问nginx版本号已经不显示了。关于nginx server名称隐藏以及php版本隐藏,这里不写了网上教程太多了....

[root@zxl-nginx conf]# curl -I http://www.zxl.com
HTTP/1.1 200 OK
Server: nginx
Date: Sat, 19 Dec 2015 14:29:30 GMT
Content-Type: text/html
Content-Length: 44
Last-Modified: Fri, 18 Dec 2015 05:23:18 GMT
Connection: keep-alive
ETag: "56739846-2c"
Accept-Ranges: bytes


4:nginx访问状态,查看nginx编译参数是否加入--with-http_stub_status_module,如没有请自行重新添加nginx状态模块参数重新编译即可,编译之前需备份nginx配置文件以及nginx启动程序即可。

[root@zxl-nginx ~]# nginx -V
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module

5:修改nginx配置,在server段中添加内容如下

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

技术分享

6:检测nginx配置以及重新加载

[root@zxl-nginx conf]# 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
[root@zxl-nginx conf]# nginx -s reload

7:nginx访问状态内容如下

技术分享


访问状态参数说明

Active connections:3    #nginx 正处理的活动连接数3个。
server accepts handled requests
 42 42 386
 
第一个server表示nginx启动到现在一共处理了42个连接
第二个accepts表示nginx启动到现在成功创建了42次握手,请求丢失数=(握手数-连接数),可以看出本次状态没有丢失请求
第三个handled requests,表示总共处理了386次请求

                  

Reading: 0 Writing: 1 Waiting: 2
#Reading :nginx读取到客户端的Header信息数。
#Writing : nginx返回给客户端的Header信息数。
#Waiting : 开启 keep-alive 的情况下,这个值等于 active - (reading + writing),意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接。
这个状态信息,从nginx启动算起,包括重载配置文件,也会清零


本文出自 “流鼻涕” 博客,请务必保留此出处http://noodle.blog.51cto.com/2925423/1726467

nginx版本隐藏以及访问状态

标签:nginx隐藏版本号 nginx访问状态

原文地址:http://noodle.blog.51cto.com/2925423/1726467

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!