文章目录
一、Nginx 服务优化
1.1、配置Nginx 隐藏版本号
查看版本号方法:
使用fiddler工具在 Windows客户端查看 Nginx版本号
在 CentOS系统中使用“curl -l 网址”命令查看
隐藏Nginx版本号,避免安全漏洞泄露
Nginx隐藏版本号的方法
修改配置法
修改源码法
1.1.1、修改配置文件
启动Nginx,查看当前Nginx版本号
[root@localhost ~]# nginx ## 启动nginx
[root@localhost ~]# curl -I http://20.0.0.25 ## 查看 nginx 版本号
HTTP/1.1 200 OK
Server: nginx/1.15.9 ## 版本号
Date: Sun, 06 Sep 2020 05:59:52 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 03 Sep 2020 02:47:02 GMT
Connection: keep-alive
ETag: "5f505926-264"
Accept-Ranges: bytes
修改配置文件
[root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream; ##在这下面
server_tokens off; ## 手动添加这一行,隐藏版本号
重启Nginx,再次查看版本号
[root@localhost ~]# killall -s HUP nginx ## 重启nginx
[root@localhost ~]# curl -I http://20.0.0.25
HTTP/1.1 200 OK
Server: nginx ## 版本号已隐藏
Date: Sun, 06 Sep 2020 06:10:33 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 03 Sep 2020 02:47:02 GMT
Connection: keep-alive
ETag: "5f505926-264"
Accept-Ranges: bytes
1.1.2、修改源码
Nginx源码文件/usr/src/ nginx-1.12.2/src/ core/nginx. h包含了版本信息,可以随意设置
重新编译安装,隐藏版本信息
[root@localhost ~]# vi /root/nginx-1.15.9/src/core/nginx.h
#define nginx_version 1015009
#define NGINX_VERSION "1.1.1.1" #版本号
#define NGINX_VER "IIS/" NGINX_VERSION #软件类型
#重新编译安装#
[root@localhost ~]# cd nginx-1.15.9/
[root@localhost nginx-1.15.9/]# ./configure
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module
[root@localhost nginx-1.15.9/]# make -j3
[root@localhost nginx-1.15.9/]# make install
[root@localhost nginx-1.15.9/]# vi /usr/local/nginx/con