查看Nginx安装目录
使用命令 which nginx 和 whereis nginx 。 前者只适用于软件的安装目录被添加进了系统 Path 的的情况。
查看 nginx 配置文件所在目录
使用命令 find / | grep nginx.conf 。其作用为:查找 (find) ,在系统根目录 (/) 及其子目录下,所有名为 nginx.conf 的文件。
执行结果如下:
/usr/xxxx/www-servers/nginx/files/nginx.conf
/etc/nginx/nginx.conf
我们得到两条结果,说明存在两个 Nginx 配置文件。第二步,需要确认当前运行的服务器使用的是哪个配置文件。
确认 Nginx 启动的是哪个配置文件
使用命令 ps -ef | grep nginx 。其作用为:查看正在运行的名叫 nginx 的进程 (ps)。
-e : 显示所有进程。
-f : 全格式。
执行结果如下:
root 22524 1 0 06:47 ? 00:00:00 nginx: master process nginx -c /etc/nginx/nginx.conf
nginx 22525 22524 0 06:47 ? 00:00:00 nginx: worker process
root 22634 22471 0 07:16 pts/1 00:00:00 grep --colour=auto nginx
从第一行末尾可以看到,当前启动的是 /etc/nginx/nginx.conf 。
退出和停止 Nginx
nginx -s quit 和 nginx -s stop 。
启动 Nginx
nginx -c /etc/nginx/nginx.conf 。
注:文中提到的命令在 linux 中非常实用,可用于查找任意软件和文件。