How to solve the problem of hiding version number and WEB server information in nginx

10-30-2023

Nginx can not only hide version information, but also support custom web server information.

Let's look at the final hidden result first.

How to achieve it is actually very simple, please read on.

1 official website downloads the latest stable version.

wget http://nginx.org/download/nginx-1.14.1.tar.gz

2 decompression

tar -xf nginx-1.14.1.tar.gzcd nginx-1.14.1

3 modify the c file

(1) vimsrc/http/ngx _ http _ header _ filter _ module.c # modify line 49.

static u_char ngx_http_server_string

(2) vimsrc/http/ngx _ http _ special _ response.c # modify line 36 "please guess it!" Crlf # Write the string just now again.

4 compilation configuration

./configure --prefix=/usr/local/nginx

5 compilation and installation

make && make install

6 modify nginx configuration file and add server_tokens off under http node.

vim /usr/local/nginx/conf/nginx.conf....http {server_tokens off; .....

7 start nginx

/usr/local/nginx/sbin/nginx

8 test

Description:

(1) If you only want to hide the version number and don't want to customize the server information, you don't need to perform step 3.

(2) If you need to customize the string while upgrading nginx, there is no problem. You can modify the C file first->./configure-> make.

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us