Linux下检测Nginx安装目录,修改配置,重启

查看Nginx安装目录

使用命令 which nginxwhereis 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 quitnginx -s stop

启动 Nginx

nginx -c /etc/nginx/nginx.conf


注:文中提到的命令在 linux 中非常实用,可用于查找任意软件和文件。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。