Home > Operation and Maintenance > Safety > How to hide our Nginx version number

How to hide our Nginx version number

王林
Release: 2023-06-09 20:55:10
forward
2027 people have browsed it

How to hide our Nginx version number

Introduction

When we use Nginx for proxy, all network requests are distributed through Nginx. As long as it is software, there will be loopholes.

Nginx will inevitably have some vulnerabilities, and Nginx is also constantly undergoing version iterations, so we need to prevent the outside world from obtaining our when accessing externally.

Nginx version. Reduce some attack risks caused by version exposure. (Upgrading to the latest version in time will provide higher security.)

This article introduces how to hide the version number of our Nginx to avoid external attacks.

1. How to check whether the Nginx version of your own server is hidden

The following introduces the query methods in different environments

(1) windows Environment

We can access the web page through the browser, press F12 to enter the inspection mode, and through the Network panel we can see all the network requests of the current page

Find an interface and click on it. You can see the following data through the Headers panel under the pop-up request details: Server The version number of your nginx will be displayed later:

Accept-Ranges: bytes
Access-Control-Allow-Credentials: true
Access-Control-Allow-Headers: Content-Type,ADMIN-Authorization,API-Authorization
Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS
Access-Control-Max-Age: 3600
Cache-Control: public,max-age=60,s-maxage=60
Content-Encoding: gzip
Content-Length: 3348
Content-Type: application/javascript
Date: Fri, 23 Sep 2022 01:55:37 GMT
Last-Modified: Tue, 08 Mar 2022 07:14:08 GMT
Server: nginx/1.23.0
Vary: Origin
Copy after login

The above example is an example where the nginx version number is exposed. If the version number is hidden, It will be displayed as:

Server: nginx/ There will be a version number. (2) In Linux environment

Compared with the query method in windows, Linux query can be queried directly through the

curl -I command .

For example, check the effect of this site:

[root@iZuf63tu3fn1swasqa62h8Z nginx]# curl -I zinyan.com
HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Fri, 23 Sep 2022 02:09:49 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: https://zinyan.com/
Copy after login

If the nginx version is not hidden, the version number will be added after nginx.

2. Hide Nginx version

The hiding method is relatively simple: you need to open the nginx.conf configuration file. (Usually the file directory is

/etc/nginx/nginx.conf)

Switch to the directory where the nginx.conf file is located and use

vim nginx.conf Open the file. (Press I to enter edit mode)

Then add under the server level:

server_tokens off; If there is server_tokens originally, change the value is on, if not, add the whole.

The effect is as follows:

http{
...
server{
listen 80 default_server;
listen [::]:80 default_server;
server_name_;
root /usr/share/nginx/html;
server_tokens off;#添加这一项就可以了
location / {
}
error_page 404 /404.html;
location = /40x.html {
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
}

} 
}
Copy after login

After adding, press the

Esc key to exit the editing mode, and then enter :wq Just save and exit. (If you are not familiar with vim commands, you can learn about them through https://zinyan.com/?p=23)

Final execution:

nginx -s reload
Copy after login

Just restart nginx. This will allow you to hide the version.

By default, nginx does not hide the version number. We need to actively configure it ourselves.

The above is the detailed content of How to hide our Nginx version number. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:51cto.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template