1.修改Nginx的源码
#查看版本信息
/usr/local/nginx/sbin/nginx -v
nginx version: nginx/1.18.0
#切换Nginx目录
cd /root/nginx-1.18.0
#查看Nginx目录
ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE Makefile man objs README src
#清除编译信息,因为之前编译过
make clean
#查看清除编译信息后Nginx目录,少了Makefile文件 、objs 目录
ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE man README src
#修改源码软件名称和版本信息
sed -i "s#\#define NGINX_VERSION \"1.18.0\"#\#define NGINX_VERSION \"8.8.0\"#g" /root/nginx-1.18.0/src/core/nginx.h
sed -i "s#\#define NGINX_VER \"nginx/\" NGINX_VERSION#\#define NGINX_VER \"Web/\" NGINX_VERSION#g" /root/nginx-1.18.0/src/core/nginx.h
2.修改Nginx的头部信息(headers)
#在开发者模式,查看Nginx的头部信息
#替换connection字段
sed -i "s#static u_char ngx_http_server_string\[\] = \"Server: nginx\" CRLF;#static u_char ngx_http_server_string\[\] = \"Server: Web\" CRLF;#g" /root/nginx-1.18.0/src/http/ngx_http_header_filter_module.c
3.重新编译Nginx
#停掉Nginx
/usr/local/nginx/sbin/nginx -s stop
#强制删除Nginx目录
rm -rf /usr/local/nginx/
#切换到解压的Nginx目录
cd /root/nginx-1.18.0
#检查编译环境
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-pcre
#编译Nginx源包和安装Nginx源包
make && make install
#赋予所属用户和所属用户组
chown -R nginx:nginx /usr/local/nginx/
#启动Nginx服务
/usr/local/nginx/sbin/nginx
#查看版本信息
/usr/local/nginx/sbin/nginx -v
nginx version: Web/8.8.0
#查看头部信息和返回错误页面信息
curl -i -X head 172.25.0.20
HTTP/1.1 400 Bad Request
Server: Web/8.8.0
Date: Sun, 24 May 2020 16:11:43 GMT
Content-Type: text/html
Content-Length: 154
Connection: close
<html>
<head><title>400 Bad Request</title></head>
<body>
<center><h1>400 Bad Request</h1></center>
<hr><center>Web/8.8.0</center>
</body>
</html>
#查看错误页面的信息