文件:src/core/nginx.h
#define NGINX_VERSION "1.4.7"
#define NGINX_VER "nginx/" NGINX_VERSION
修改為:
#define NGINX_VERSION "1.4.7"
#define NGINX_VER "jdws/" NGINX_VERSION // 偽裝為任意名稱
此處修改通常已足夠生效。
文件:src/http/ngx_http_header_filter_module.c
static char ngx_http_server_string[] = "Server: nginx" CRLF;
修改為:
static char ngx_http_server_string[] = "Server: jdws" CRLF;
文件:src/http/ngx_http_special_response.c
static u_char ngx_http_error_tail[] =
"<hr><center>nginx</center>" CRLF
"</body>" CRLF "</html>" CRLF;
修改為:
static u_char ngx_http_error_tail[] =
"<hr><center>jdws</center>" CRLF
"</body>" CRLF "</html>" CRLF;
./configure --prefix=/usr/local/nginx
make && make install
/usr/local/nginx/sbin/nginx -s reload
nginx.conf 中 http 塊添加:
http {
server_tokens off;
}
| 配置 | 響應頭 Server | 錯誤頁底部 |
|---|---|---|
| 默認 | nginx/1.4.7 | nginx |
| 修改源碼 | jdws/1.4.7 | jdws |
| server_tokens off | nginx | nginx(版本號隱藏) |
| 源碼修改 + server_tokens off | jdws | jdws |
server_tokens off 後,響應頭僅顯示 Server: nginx(或偽裝名),版本號隱藏ngx_http_error_tail 控制,server_tokens off 不影響