隐藏版本号
- 在生产环境中,需要隐藏Nginx的版本号,以免泄露Nginx的版本,使攻击者不能针对特定版本进行攻击。
查看方法 - 使用fiddler工具在Windows客户端中查看Nginx版本
- 在CentOS系统中使用“curl -I 网址” 命令查看
隐藏版本号的方法
- 修改配置文件法
- 修改源码法
修改配置文件法
1、进入到配置文件中添加代码
vim /usr/local/nginx/conf/nginx.conf
server_tokens off;
重启Nginx服务
2、使用curl -I 查看版本号
修改源码法
1、修改nginx 源码文件,源码文件中包含了版本信息,然后再重新编译安装,就隐藏了真实的版本信息
vim nginx-1.12.2/src/core/nginx.h
2、重新编译
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
make && make install
3、重启Nginx服务
[root@02 nginx-1.12.2]# systemctl stop nginx.service
[root@02 nginx-1.12.2]# systemctl start nginx.service
4、再次查看版本号
配置页面压缩
当nginx 将网页数据返回给客户端后,可设置缓存时间,以方便日后进行相同内容请求时直接返回,避免重复请求,加快访问速度,一般只针对静态资源进行设置,对动态网页不用设置缓存时间。
1、第一步、将图片复制到Nginx的工作目录里
[root@localhost html]# cp lbjn.jpg /usr/local/nginx/html/
2、修改配置文件,在location里添加expires参数,并指定缓存时间
重启Nginx服务
[root@localhost html]# systemctl stop nginx.service
[root@localhost html]# systemctl start nginx.service
3、接下来使用抓包看到修改后的缓存时间