nginx入门安全优化--隐藏版本号的两种方式

方式一:基于修改配置文件

# vim /usr/local/nginx/conf/nginx.conf//编辑主配置文件
//第二十行添加
http {
    include       mime.types;
    default_type  application/octet-stream;
    server_tokens off;# service nginx reload               //重启服务
    # curl -I http://192.168.116.133     //再次检测

在这里插入图片描述
方式二:(前提条件:nginx是编译安装)基于修改源码包文件
注意:先修改源码包文件再进行编译安装,如果是已经编译安装了nginx,修改源码包文件后重新编译安装一下。
我这里是先修改源码包又进行的编译安装。

[root@zabbix nginx-1.16.1]# vim ./src/core/nginx.h   修改源码包文件
#define nginx_version      1012000
#define NGINX_VERSION      "1.1.5"
#define NGINX_VER          "IIS/" NGINX_VERSION
//更改版本号,注意不用取消井号!

修改后进行编译安装

[root@zabbix nginx-1.16.1]# ./configure --prefix=/application/nginx-1.16.1/ --sbin-path=/usr/bin/ --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --add-module=../ngx_cache_purge-2.3

安装完成后测试查看

[root@zabbix nginx-1.16.1]# curl -I  10.0.0.71
HTTP/1.1 200 OK
Server: IIS/1.1.5     #注意这里,已经改变
Date: Sun, 29 Mar 2020 01:37:38 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Sun, 29 Mar 2020 01:37:09 GMT
Connection: keep-alive
ETag: "5e7ffbc5-264"
Accept-Ranges: bytes
发布了224 篇原创文章 · 获赞 19 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weixin_42506599/article/details/105173609