首先需要防止Nginx透露其版本信息。

默认情况下,Nginx在HTTP报头中显示其名称和版本,为了防止Nginx透露其版本信息。

你可以用下列命令来检查:

curl -I http://localhost 

应该会看到下列输出:

HTTP/1.1 200 OK

Server: nginx/1.41.4 (Ubuntu) 

Date: Thu, 18 Apr 2019 16:17:04 GMT

Content-Type: text/html; charset=utf-8

Content-Length: 3153

Last-Modified: Wed, 21 Nov 2018 18:48:23 GMT

Connection: keep-alive

ETag: "5bf5a877-c51"

Accept-Ranges: bytes

在上述输出中,会看到Nginx和操作系统的版本。

隐藏X-Powered-By

    修改 php.ini 文件。添加或修改 expose_php = Off

可以编辑/data/nginx/nginx.conf(调整为您的域名指向文件),隐藏这部分信息:

vi /data/nginx/nginx.conf 

在http配置部分里面添加server_tokens off这一行:

http { 

## 

# Basic Settings 

## 

server_tokens off; 

}

完成之后保存并关闭文件。

重启nginx,调整为您的nginx路径。

/data/nginx/sbin/nginx -s reload

再次运行curl命令:

curl -I http://localhost 

HTTP/1.1 200 OK

Server: nginx

Date: Thu, 18 Apr 2019 16:17:04 GMT

Content-Type: text/html; charset=utf-8

Content-Length: 3153

Last-Modified: Wed, 21 Nov 2018 18:48:23 GMT

Connection: keep-alive

ETag: "5bf5a877-c51"

Accept-Ranges: bytes