你说的“查 nginx 来源”可能有几种不同含义,下面我按常见场景分别说明,你可以对照自己的需求来看。
# Debian / Ubuntu
dpkg -l | grep nginx
# 或
apt list --installed | grep nginx
# CentOS / Rocky / Alma
rpm -qa | grep nginx
yum list installed | grep nginx
which nginx
# 或
whereis nginx
nginx -V
输出里能看到:
--prefix=--with-xxxnginx.org)nginx -t
会显示:
nginx: configuration file /etc/nginx/nginx.conf test is successful
查看加载了哪些配置:
nginx -T
tail -f /var/log/nginx/access.log
示例:
192.168.1.10 - - [time] "GET / HTTP/1.1" 200
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr | head
awk -F\" '{print $4}' /var/log/nginx/access.log | sort | uniq -c | sort -nr
或:
grep "Referer" /var/log/nginx/access.log
ps -ef | grep nginx
或:
systemctl status nginx
file $(which nginx)
nginx -V
如果看到:
/usr/local/nginx基本就是源码编译安装。
| 你想查的 | 命令 |
|---|---|
| 安装方式 | dpkg -l / rpm -qa |
| 二进制位置 | which nginx |
| 编译来源 | nginx -V |
| 配置来源 | nginx -T |
| 访问来源 IP | access.log |
| 请求来源域名 | Referer |
| 启动来源 | systemctl status nginx |
如果你能补充一句:
我想查的是「nginx 安装来源 / 访问来源 / 请求来源 / 配置来源」
我可以直接给你最精准的一条命令。