目录
一、隐藏nginx版本号
1.1查看版本号
方法一:curl命令
-
可以在 CentOS 中使用命令
curl -I http://192.168.59.118
显示响应报文首部信息。curl -I http://192.168.59.118
方法二:在网页中查看
1. #切换至html目录,拖一个图片进去
cd /usr/local/nginx/html
2. #在网页中查看
http://192.168.59.118/game.png
1.2隐藏版本信息
方法一:修改配置文件
1.#修改配置文件
vim /usr/local/nginx/conf/nginx.conf
2.#重启nginx
systemctl restart nginx
3.#查看版本是否被隐藏
curl -I http://192.168.59.118
```handlebars
http {
include mime.types;
default_type application/octet-stream;
server_tokens off; #添加,关闭版本号
......
}
方法二: 修改源码文件,重新编译安装
1. #切换至nginx安装包所在目录
cd /opt/
2. #停止nginx服务
systemctl stop nginx.service
3. #切换至安装目录
cd nginx-1.12.0/
4. #切换至内核目录
cd src/core/
5. #进入配置文件
vim nginx.h
#define NGINX_VERSION "yxp"
#define NGINX_VER "yyy/" NGINX_VERSION
6. #切换至文件目录
cd ../../
7. #编译
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
8. #安装
make && make install -j4
9. #将配置文件下的之前关闭版本信息开启
vim /usr/local/nginx/conf/nginx.conf
server_tokens on;
10. #重启nginx
systemctl restart nginx
11. #查看版本信息
curl -I http://192.168.59.118