1、隐藏版本号
隐藏版本号很简单,只要修改nginx.conf配置文件即可,在http模块中添加如下配置:
server_tokens off;
2、修改server名称
正常的请求响应中会有如下的字段:
Server: nginx/1.14.1
如果想修改这个名称需要修改nginx源码,然后重新编译,
A、修改src/core/nginx.h文件
源代码如下:
#define NGINX_VERSION "1.14.1"
#define NGINX_VER "nginx/" NGINX_VERSION
修改后:
#define NGINX_VERSION "1.14.1"
#define NGINX_MY "wyq"
#define NGINX_VER NGINX_MY "/" NGINX_VERSION
B、修改src/http/ngx_http_header_filter_module.c文件
源代码如下:
static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
修改后:
static u_char ngx_http_server_string[] = "Server: " NGINX_MY CRLF;
C、修改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>" NGINX_VER "</center>" CRLF
"</body>" CRLF
"</html>" CRLF
;
D、修改 html/ 目录下的html文件,去掉nginx相关字眼,或者直接更改样式、文字等