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
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 thecurl -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/
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 usevim 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 {
}
}
}
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
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use