一般nginx服務器不隱藏服務器類型及版本信息
curl -I http://www.aaa.com
獲取web服務器的類型和版本代碼
HTTP/1.1 200 OK
Server: nginx nginx/0.8.53
Date: Tue, 14 Dec 2010 08:10:06 GMT
Content-Length: 151
Last-Modified: Mon, 13 Dec 2010 09:39:55 GMT
Connection: keep-alive
Accept-Ranges: bytes
這對於服務器安全來講是個隱患,用如下方法能夠改善這種狀況
1. 編輯源代碼../src/http/ngx_http_header_filter_module.c
修改前代碼
48 static char ngx_http_server_string[] = 「Server: nginx」 CRLF;
49 static char ngx_http_server_full_string[] = 「Server: 」 NGINX_VER CRLF;
改成
修改後代碼
48 static char ngx_http_server_string[] = 「Server: test 1.0 」 CRLF;
49 static char ngx_http_server_full_string[] = 「Server: test 1.0 」 NGINX_VER CRLF;
而後編譯安裝。
2. 編輯/usr/local/nginx/conf/nginx.conf,添加
server_tokens off;
從新啓動nginx
/usr/local/nginx/sbin/nginx -s reload
最終結果以下
curl -I http://www.aaa.com
被修改後的服務器信息代碼
HTTP/1.1 200 OK
Server: test 1.0
Date: Tue, 14 Dec 2010 08:24:32 GMT
Content-Type: text/html
Content-Length: 151
Last-Modified: Mon, 13 Dec 2010 09:39:55 GMT
Connection: keep-alive
Accept-Ranges: bytes