Nginx 优化(隐藏版本号,防盗链等)

一、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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值