配置

--下载nginx
wget http://nginx.org/download/nginx-1.18.0.tar.gz

--解压源码包
tar zxf nginx-1.18.0.tar.gz
cd /nginx-1.18.0

修改nginx源码

将下载后的nginx源码解压,需要对以下几个文件做出修改。这里我们演示将nginx服务器名称修改为`end`
--文件一:src/core/nginx.h

#define NGINX_VER          "nginx/" NGINX_VERSION
//修改为
#define NGINX_VER          "end/" NGINX_VERSION

#define NGINX_VAR          "NGINX"
//修改为
#define NGINX_VAR          "END"
--文件二: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: end" CRLF;
--文件三:src/http/ngx_http_special_response.c
"<hr><center>nginx</center>" CRLF
//修改为
"<hr><center>end</center>" CRLF
--文件四:src/http/v2/ngx_http_v2_filter_module.c
"http2 output header: \"server: nginx\"");
//修改为
"http2 output header: \"server: end\"");
通过修改上面4个文件,已经`nginx`服务器名修改为了end,如果不想去找到文件一个一个修改,也可以使用sed命令直接替换
--执行更名操作
sed -i "s#\"NGINX\"#\"end\"#" src/core/nginx.h
sed -i "s#\"nginx/\"#\"END/\"#" src/core/nginx.h
sed -i "s#Server: nginx#Server: end#" src/http/ngx_http_header_filter_module.c
sed -i "s#\"<hr><center>nginx<\/center>\"#\"<hr><center>end<\/center>\"#" src/http/ngx_http_special_response.c
sed -i "s#server: nginx#server: end#"

验证

修改完毕后,需要将源码重新编译,如何编译`nginx`这篇文章不做描述,具体请网上搜索。我们可以使用`curl`命令来测试是否修改成功,执行测试命令`curl -I https://www.endvv.com返回的结果如下,可以看到Server那里已经变为`END`

root@linux:/# curl -I https://www.endvv.com
HTTP/1.1 200 OK
Date: Tue, 29 Dec 2020 20:59:59 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
Server: end
Last-Modified: Tue, 29 Dec 2020 20:50:00 GMT
X-NWS-UUID-VERIFY: 03ecd87e3b61c53c581ddd729da6ce58
Set-Cookie: PHPSESSID=6gd3gdc0k66p9j93ephiqa0718; path=/
X-Pingback: https://www.endvv.com/action/xmlrpc
Set-Cookie: 9a7952d23e64755848d8262c9340e181latest_time_id=163; path=/
X-Daa-Tunnel: hop_count=4
X-NWS-LOG-UUID: e3324ce7-197f-47e5-8189-04701710224c
X-Cache-Lookup: Hit From Upstream
X-Cache-Lookup: Hit From Inner Cluster
X-Cache-Lookup: Hit From Upstream
X-Cache-Lookup: Hit From Inner Cluster
Last modification:December 30th, 2020 at 05:00 am
如果觉得我的文章对你有用,请随意赞赏