一、隐藏版本号
可以使用 Fiddler 工具抓取数据包,查看 Nginx版本,也可以在 CentOS 中使用命令 curl -I http://192.168.223.10 显示响应报文首部信息
curl -I http://IP #换上自己的ip
方法一:修改配置文件方式
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://ip
重启nginx服务后生效
方法二:修改源码文件,重新编译
vim /opt/nginx-1.15.9/src/core/nginx.h #修改nginx头文件
#define NGINX_VERSION "1.1.1" #修改版本号
#define NGINX_VER "IIS" NGINX_VERSION #修改服务器类型
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--add-module=/usr/local/nginx-module-vts-master/
make && make install
systemctl restart nginx
curl -I http://ip
如果先使用了方法一
记得开启版本号
二、修改用户与组
vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; #取消注释,修改用户为 nginx ,组为 nginx
systemctl restart nginx
ps aux | grep nginx
主进程由root创建,子进程由nginx创建