Step 1: Open your Nginx server configuration file /etc/nginx/nginx.conf
(it’s the default path, however it might change based on your installation) and add server_tokens off
; in the http
section as shown below:
#vim /etc/nginx/nginx.conf
http { #Hide nginx version server_tokens off; }
Step 2: Open the file /etc/nginx/fastcgi_params
#vim /etc/nginx/fastcgi_params
Replace the line:
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
With:
fastcgi_param SERVER_SOFTWARE nginx;
How to hide PHP version number:
Open the file /etc/php.ini
and add expose_php = Off
. This will disable the PHP header information.This step removes the PHP header information everywhere.
#vim /etc/php.ini
expose_php = Off
How to restart PHP-FPM and Nginx services on CentOS7
#systemctl restart php-fpm #systemctl restart nginx
How to view your web-server header information
Verify your modifications:
$curl -I http://localhost.local HTTP/1.1 200 OK Server: nginx Date: Mon, 2 Aug 2018 15:13:47 GMT Content-Type: text/html; charset=UTF-8 Connection: keep-alive Vary: Accept-Encoding