下载 nginx-1.19.1.tar.gz
操作步骤:
[root@Test ~]# tar -xzvf nginx-1.19.1.tar.gz
修改ngx_http_header_filter_module.c 文件
[root@Test ~]# vim nginx-1.19.1/src/http/ngx_http_header_filter_module.c
需要修改:
static u_char ngx_http_server_string[] = "Server: nginx" CRLF;
static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF;
static u_char ngx_http_server_build_string[] = "Server: " NGINX_VER_BUILD CRLF;
修改成:
static u_char ngx_http_server_string[] = "Server: unknow" CRLF;
static u_char ngx_http_server_full_string[] = "Server: unknow" CRLF;
static u_char ngx_http_server_build_string[] = "Server: unknow" CRLF;
重新编译:
./configure --prefix=/usr/local/nginx && make && make install
编译报错信息:
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
解决方法:
[root@Test ~]# yum -y install openssl openssl-devel
注:非root用户要启动1024下的端口
setcap cap_sys_admin,cap_net_bind_service,cap_sys_resource+ep /usr/local/nginx/sbin/nginx
重启 nginx
[root@Test ~]# systemctl restart nginx

本文详细介绍如何通过修改源码的方式隐藏Nginx服务器的版本信息,包括下载Nginx源码、修改ngx_http_header_filter_module.c文件的具体步骤,以及在非root用户下启动Nginx的方法。
3645

被折叠的 条评论
为什么被折叠?



