Nginx優化實用技巧之隱藏版本號
- 隱藏版本號
- 修改版本配置
- 重啟服務
- 查看版本號
- 修改版本號
- 修改組態檔
- 重新編譯
- 重啟服務并查看版本號
隱藏版本號
- 正常我們的nginx中的版本號都是正常顯示的,但是這樣容易收到針對版本弱點的攻擊,所以這里我們將其版本號隱藏,
這是正常情況下的顯示
修改版本配置
vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server_tokens off; #添加,關閉版本號
......
}


重啟服務
systemctl restart nginx.service

查看版本號
-
再次進入,查看版本號,發現只剩下nginx了

-
或者我們通過命令的方式也能夠進行查看
curl -I http://192.168.199.40

修改版本號
- 我們還可以通過修改版本號的方式來進行掩蓋
修改組態檔
vim /opt/nginx-1.12.0/src/core/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 install
vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server_tokens on;
......
}



重啟服務并查看版本號
- 這時候我們發現版本號已經更改成我們自己所設定的版本了
cd /opt/nginx-1.12.0/
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module
make && make install
vim /usr/local/nginx/conf/nginx.conf
http {
include mime.types;
default_type application/octet-stream;
server_tokens on;
......
}

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/249017.html
標籤:其他
下一篇:Nginx反向代理和負載均衡
