#### 查找nginx的配置文件
首先,要清楚自己的机器上是否已经安装了Nginx和Nginx的安装目录(手动狗头),如果忘记了是否已安装Nginx或安装目录,那么首先通过ps命令查看是否有nginx在运行:
```
[root@miantiao ~]# ps -ef | grep nginx
root 11964 1 0 17:23 ? 00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx 11965 11964 0 17:23 ? 00:00:00 nginx: worker process
root 20913 20829 0 20:23 pts/0 00:00:00 grep --color=auto nginx
```
第一条信息则说明了已安装并且Nginx的配置文件的位置在/etc/nginx目录下为nginx.conf。
如果ps命令执行后没有nginx信息,那么就启动B计划,执行 whereis命令:
```
[root@miantiao ~]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
```
然后分别进入每一个目录,直到找到nginx.conf文件(一般情况下,配置文件都在/etc/nginx目录下)。
如果上述方法都不行,那就用which命令,查找nginx可执行文件的位置:
```
[root@miantiao modules]# which nginx
/usr/sbin/nginx
```
找到了nginx可执行文件的路径,就可以通过Nginx自身的功能找到配置文件的位置了,即执行/usr/sbin/nginx -t命令。
```
[root@miantiao modules]# /usr/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
```
这下就找到了nginx的配置文件nginx.conf的位置了,即在/etc/nginx/目录下
#### 修改nginx的配置文件
打开Nginx的conf配置文件Nginx.conf,在http{}块中添加server_tokens off:
```
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
server_tokens off;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
```
然后重启Nginx。
#### 效果
修改完后,执行命令curl -I localhost,可以看到Server只有服务器名nginx,没有了版本号信息,说明隐藏nginx版本信息已生效。
```
[root@miantiao nginx]# curl -I localhost
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 05 Mar 2020 12:56:08 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Tue, 13 Aug 2019 15:04:31 GMT
Connection: keep-alive
ETag: "5d52d17f-264"
Accept-Ranges: bytes
```
完结撒花。
参考:[http://www.linuxidc.com/Linux/2017-02/140250.htm](http://www.linuxidc.com/Linux/2017-02/140250.htm)

隐藏Nginx服务器版本信息