在Linux系统中,可以通过以下几种方法查看Nginx的版本信息:
nginx -v
命令(简单版本)nginx -v
输出示例:
nginx version: nginx/1.18.0 (Ubuntu)
仅显示基础版本信息
nginx -V
命令(详细版本+编译参数)nginx -V
输出示例:
nginx version: nginx/1.18.0
built with OpenSSL 1.1.1f 31 Mar 2020
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2...'...
大写V会显示完整的编译配置参数
curl -I http://localhost
观察Server头字段:
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
...
bash
apt list --installed | grep nginx
bash
rpm -qa | grep nginx
ps aux | grep nginx
输出中的进程路径通常包含版本号
如果提示nginx: command not found
:
/usr/sbin/nginx -v
whereis nginx
查找可执行文件位置需要sudo权限的情况:
sudo nginx -v
版本信息被隐藏:
检查nginx.conf中的server_tokens
配置项是否设置为off
这些方法适用于大多数Linux发行版(Ubuntu/CentOS/Debian等)和Nginx的主流版本。根据您的具体使用场景选择最适合的方式即可。