nginx 隐藏版本号与WEB服务器信息
- 1.安装相关软件
- 2.下载软件包解压并进入
- 3.修改C文件
- 4.编译配置./configure --prefix=/usr/local/nginx
- 5.编译安装make && make install
- 5.1.错误处理1
- 5.2.错误处理2
- 5.2.编译安装make && make install
- 6.修改nginx配置文件,http节点下添加 server_tokens off
- 7.启动nginx
- 8.测试
- 9.浏览器访问测试
- 10.说明:
- endl
1.安装相关软件
yum -y install gcc make gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel nfs-utils
2.下载软件包解压并进入
wget http://nginx.org/download/nginx-1.14.1.tar.gz
tar -xf nginx-1.14.1.tar.gz && cd nginx-1.14.1
3.修改C文件
vim src/http/ngx_http_header_filter_module.c +49
(1)vim src/http/ngx_http_header_filter_module.c #修改49行
static u_char ngx_http_server_string[] = "Server: Please guess it!" CRLF; #Server后写上你自定义的服务器信息
vim src/http/ngx_http_special_response.c +36
(2)vim src/http/ngx_http_special_response.c #修改36行
"<hr><center>Please guess it!</center>" CRLF #再写一遍刚才的字符串
4.编译配置./configure --prefix=/usr/local/nginx
5.编译安装make && make install
5.1.错误处理1
make[1]: *** [objs/Makefile:781: objs/src/os/unix/ngx_user.o] Error 1
make[1]: Leaving directory '/root/nginx-1.14.1'
make: *** [Makefile:8: build] Error 2
vim src/os/unix/ngx_user.c +26
5.2.错误处理2
cc1: all warnings being treated as errors
make[1]: *** [objs/Makefile:886: objs/src/http/ngx_http_script.o] Error 1
make[1]: Leaving directory '/root/nginx-1.14.1'
make: *** [Makefile:8: build] Error 2
vim objs/Makefile
5.2.编译安装make && make install
6.修改nginx配置文件,http节点下添加 server_tokens off
vim /usr/local/nginx/conf/nginx.conf
....
http {
server_tokens off;
.....
7.启动nginx
/usr/local/nginx/sbin/nginx
8.测试
[root@node1 nginx-1.14.1]# curl -I http://127.0.0.1
HTTP/1.1 200 OK
Server: please guess it!
Date: Thu, 24 Oct 2024 08:22:49 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Thu, 24 Oct 2024 08:17:59 GMT
Connection: keep-alive
ETag: "671a02b7-264"
Accept-Ranges: bytes
......
9.浏览器访问测试
10.说明:
- (1)要是只想隐藏版本号,而不想自定义服务器信息,不需要执行第3步.
- (2)要是对nginx升级同时还要做字符串自定义,也是没有问题的,可以先修改C文件–>./configure --> make 即可