文章詳情頁
Nginx隱藏server頭信息的實現
瀏覽:18日期:2023-03-13 15:37:46
目錄
- 分析
- 隱藏版本號
- php-fpm服務器隱藏版本號
- 隱藏Server
分析
隱藏版本號
修改 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
版本號已隱藏
[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服務器隱藏版本號
如果搭建的是 php-fpm 服務器的話,還得修改 fastcgi.conf
在該配置中有這么一行
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; 修改后 fastcgi_param SERVER_SOFTWARE nginx;
隱藏Server
經過上面的修改,版本號就已經隱藏了,如果連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源碼安裝教程 https://www.jb51.net/article/142431.htm
編譯完后替換之前備份的文件,啟動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
這時Server已經變成自己定義的名字了,nginx的加固就介紹到這。
到此這篇關于Nginx隱藏server頭信息的實現的文章就介紹到這了,更多相關Nginx隱藏server頭信息內容請搜索以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持!
標簽:
Nginx
排行榜