文章目录
前言
- 在企业信息化应用环境中,服务器的安全性和响应速度需要根据实际情况进行响应参数配置,以达到最优的用户体验
- 默认的 Nginx 安装参数只能提供最基本的服务,还需要调和如网页缓存时间、连接超时、网页压缩等响应参数,才能发挥吹服务器的最大作用
一、Nginx服务优化
Nginx 前期的编译安装及配置可看我上篇博客,传送门:https://blog.csdn.net/weixin_51486343/article/details/112390348
1.隐藏版本号
在生产环境中,需要隐藏 Nginx 的版本号,以避免泄露 Nginx 的版本,使攻击者不能针对特定版本进行攻击
在隐藏前,可以使用 Fiddler 工具抓取数据包,查看 Nginx 版本
具体操作可以看我之前的博客,包括本文后续虚拟机win10中使用此软件抓包使用方法
传送门:定位——5.5 方法一
也可以在 CentSO 中使用命令查看
- 方法一:修改 Nginx 的主配置文件
vim /usr/local/nginx/conf/nginx.conf
http {
include mime. types;
default_type application/octet-stream;
server_tokens off;
#添加,关闭版本号
......
}
systemctl restart nginx
curl -I http://192.168.126.11
还有一种查看版本号的方法,回到 VMware ,打开网页进行查看
- 方法二:修改源码文件,重新编译安装
vim /opt/nginx-1.12.0/src/core/nginx.h
#define NGINX_VERSION "1.0.0"
#修改版本号
#define NGINX_VER "IIS" NGINX_VERSION
#修改服务器类型
保存退出后,重新进行编译安装
cd /opt/nginx-1.12.0/
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
make -j 4 && make install
把之前用方法一关闭的版本号显示重新打开
vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server_tokens on;
......
systemctl restart nginx
curl -I http://192.168.126.11
2.修改用户与组
vim /usr/local/nginx/conf/nginx.conf
user nginx nginx;
#取消注释,修改用户为nginx,组为nginx
systemctl restart nginx
ps aux | grep nginx