欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Nginx隱藏server頭信息的實(shí)現(xiàn)

 更新時(shí)間:2023年01月16日 09:32:01   作者:倦~  
本文主要介紹了Nginx隱藏server頭信息的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

分析

上一篇文章我們搭建了Nginx,請(qǐng)求響應(yīng)頭如下

[nginx@node01 sbin]$ curl -I 127.0.0.1:8090
HTTP/1.1 200 OK
Server: nginx/1.9.9
Date: Fri, 11 Nov 2022 14:56:38 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 11 Nov 2022 12:47:59 GMT
Connection: keep-alive
ETag: "636e447f-264"
Accept-Ranges: bytes

可看到這么一行 Server: nginx/1.9.9,暴露了服務(wù)為Nginx并且還知道了具體版本號(hào),如果有人想要攻擊我們網(wǎng)站,那么他們就會(huì)通過這種方式來獲取我們網(wǎng)站的一些信息。比如 知道了是Nginx,并且如果恰好發(fā)現(xiàn)該版本是有一些漏洞的,那么攻擊者就能夠很輕松的找到攻擊我們的方案,所以隱藏一些信息是很有必要的。

Nginx它考慮到了這方面的問題。給我們提供了一個(gè)配置 server_tokens。將該配置放到http快中就可以隱藏版本號(hào)了。

隱藏版本號(hào)

修改 nginx.conf,添加server_tokens,配置如下

worker_processes ?1;

events {
? ? worker_connections ?1024;
}

http {
? ? include ? ? ? mime.types;
? ? default_type ?application/octet-stream;
? ? server_tokens off;
? ? sendfile ? ? ? ?on;

? ? keepalive_timeout ?65;

? ? server {
? ? ? ? listen ? ? ? 8090;
? ? ? ? server_name ?localhost;
? ? ? ? ? ??
? ? ? ? location / {
? ? ? ? ? ? root ? html;
? ? ? ? ? ? index ?index.html index.htm;
? ? ? ? }
? ? }

}

重啟nginx

版本號(hào)已隱藏

[nginx@node01 sbin]$ ./nginx -s reload

[nginx@node01 sbin]$ curl -I 127.0.0.1:8090
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 11 Nov 2022 15:08:55 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 11 Nov 2022 12:47:59 GMT
Connection: keep-alive
ETag: "636e447f-264"
Accept-Ranges: bytes

php-fpm服務(wù)器隱藏版本號(hào)

如果搭建的是 php-fpm 服務(wù)器的話,還得修改 fastcgi.conf

在該配置中有這么一行

fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;
修改后
fastcgi_param  SERVER_SOFTWARE    nginx;

隱藏Server

經(jīng)過上面的修改,版本號(hào)就已經(jīng)隱藏了,如果連Server信息都不想讓別人知道,那就只能修改源碼了

修改C文件 src/http/ngx_http_header_filter_module.c

大概在50行左右,將nginx修改為 其它名字

//static char ngx_http_server_string[] = "Server: nginx" CRLF;
//static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
static char ngx_http_server_string[] = "Server: juan" CRLF;
static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;

重新編譯前記得停掉Nginx 備份自己的nginx.conf

Nginx源碼安裝教程 http://www.dbjr.com.cn/article/142431.htm

編譯完后替換之前備份的文件,啟動(dòng)Nginx

[nginx@node01 sbin]$ curl -I 127.0.0.1:8090
HTTP/1.1 200 OK
Server: juan
Date: Fri, 11 Nov 2022 15:34:27 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Fri, 11 Nov 2022 15:30:46 GMT
Connection: keep-alive
ETag: "636e6aa6-264"
Accept-Ranges: bytes

這時(shí)Server已經(jīng)變成自己定義的名字了,nginx的加固就介紹到這。

到此這篇關(guān)于Nginx隱藏server頭信息的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Nginx隱藏server頭信息內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論