Nginx安装完成之后,可以根据Nginx的运行命令获取加载的配置文件。
一般情况下名称是nginx.conf,可能在以下几个文件夹中:
- /usr/local/nginx/conf
- /etc/nginx
- /usr/local/etc/nginx
- /opt/nginx/conf
具体加载的配置文件在哪,以下文为准
执行以下命令,看正在运行的Nginx进程的信息
$ ps -aux | grep nginx
root 2139 0.0 0.0 148084 3152 ? Ss 09:24 0:00 nginx: master process /opt/nginx/sbin/nginx
或者
root 21113 0.0 0.0 63304 920 ? Ss 12:49 0:00 nginx: master process nginx
或者
root 23064 0.0 0.0 76156 2816 ? Ss 12:54 0:00 nginx: master process /opt/nginx/sbin/nginx -c /etc/nginx/nginx.conf
正常情况下会出现多个进程,我们只找nginx: master process,主进程,主进程后边的命令是不固定的。
如果后边是命令的后边有 -c /etc/nginx/nginx.conf,如上图中第三种情况,那么配置文件就是 -c后的文件,这种是指定配置文件启动的。如果没有-c 参数,那么需要使用命令查找加载的默认配置文件。总的来说就是Nginx的启动命令,加 -t ,这个命令是校验配置文件,后边不加其他参数,校验的就是默认配置文件,不管校验成功还是失败,都会把配置文件路径打印出来。。
如果启动命令是/opt/nginx/sbin/nginx,那么执行
$ sudo /opt/nginx/sbin/nginx -t
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
如果启动命令是nginx,那么执行
$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful