目录
隐藏nginx版本号
可以使用 Fiddler 工具抓取数据包,查看 Nginx版本,
也可以在 CentOS 中使用命令 curl -I http://192.168.217.120 显示响应报文首部信息。
curl -I http://192.168.217.120
方法一:
修改配置文件方式
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.217.120
方法二:
vim /opt/nginx-1.12.0/src/core/nginx.h
cp nginx.h abk_nginx.h #修改前建议备份一下
#define NGINX_VERSION "1.1.1" #修改版本号
#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 && make installvim /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.217.120
修改用户与组
#修改配置文件
vim /usr/local/nginx/conf/nginx.conf
user nginx nginx; #取消注释,修改用户为 nginx ,组为nginx
#重启服务
systemctl restart nginx
#查看是否修改成功
ps aux | grep nginx
缓存时间
当Nginx将网页数据返回给客户端后,可设置缓存的时间,以方便在日后进