隐藏 Nginx 版本号

1,011 阅读1分钟

Nginx 默认是显示版本号的,如:

$ curl -I share.vhost.test.cn

HTTP/1.1 200 OK

Server: nginx/1.10.3

Date: Sat, 19 Oct 2019 07:46:28 GMT

Content-Type: text/html

Connection: keep-alive

Vary: Accept-Encoding

#进入 nginx 配置文件的目录

$ vim nginx.conf

在 http {}里加上 server_tokens off;

http {
	...
	server_tokens off; 
	...
}

#编辑 php-fpm 配置文件,如 fastcgi.conf 找到:

fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;

改为:

fastcgi_param SERVER_SOFTWARE nginx;

#重新加载 nginx 配置

$ systemctl reload nginx