Home >Backend Development >PHP Tutorial >How to hide the Nginx version number, hide the Nginx version number_PHP tutorial
Recently I learned a new command curl, which has a parameter -I that can check which website is using it. A server, such as:
zhangxiaoliudeMacBook-Pro-2:~ zhangxiaoliu$ curl -I http://nginx.org/
HTTP/1.1 200 OK
Server: nginx/1.9.8
Date: Fri, 18 Dec 2015 06:30:33 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 8347
Last-Modified: Wed, 09 Dec 2015 15 :07:16 GMT
Connection: keep-alive
Keep-Alive: timeout=15
ETag: "566843a4-209b"
Accept-Ranges: bytes
You can see that the official version of Nginx currently used is 1.9.8. Each version of nginx may have some vulnerabilities, so from a security perspective, hiding the version number will be relatively safer!
Step 1: Modify nginx configuration file
vim /usr/local/nginx/conf/nginx.conf (The path of the configuration file is determined by the directory where nginx is installed. Everyone’s is different. Because some beginners don’t understand it, they will copy and paste and then execute it. , the consequences are very serious, do not execute commands you do not understand! ), add server_tokens off;
after (or before) tcp_nodelay on;
Step 2: Modify the php-fpm configuration file
The name of the php-fpm configuration file is fastcgi.conf or fcgi.conf, vim /usr/local/nginx/conf/fastcgi.conf (in the same directory as nginx.conf), use the vim command ":/SERVER_SOFTWARE", find: fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; remove "/$nginx_version".
Step 3: Restart the nginx service
Service nginx reload (reload non-stop service restart, or use /etc/init.d/nginx reload, /etc/init.d/ contains service startup scripts, which are shell scripts), Someone may It says that service nginxd reload is not used. Whether to use nginxd or nginx depends on the name of the service startup script in /etc/init.d/