nginx的配置放在nginx.conf文件中,一般我们可以使用以下命令查看服务器中存在的nginx.conf文件。
<span style="background-color:rgba(0, 0, 0, 0)"><span style="color:#000000"><code>locate nginx.conf
/usr/local/etc/nginx/nginx.conf
/usr/local/etc/nginx/nginx.conf.default
<span style="color:#0000ff">...</span></code></span></span>
如果服务器中存在多个nginx.conf文件,我们并不知道实际上调用的是哪个配置文件,因此我们必须找到实际调用的配置文件才能进行修改。
查看nginx实际调用的配置文件
1.查看nginx路径
<span style="background-color:rgba(0, 0, 0, 0)"><span style="color:#000000"><code>ps aux|grep nginx
root <span style="color:#880000">352</span> <span style="color:#880000">0.0</span> <span style="color:#880000">0.0</span> <span style="color:#880000">2468624</span> <span style="color:#880000">924</span> ?? S <span style="color:#880000">10</span>:<span style="color:#880000">43</span>上午 <span style="color:#880000">0</span>:<span style="color:#880000">00.08</span> nginx: worker <span style="color:#0000ff">process</span>
root <span style="color:#880000">232</span> <span style="color:#880000">0.0</span> <span style="color:#880000">0.0</span> <span style="color:#880000">2459408</span> <span style="color:#880000">532</span> ?? S <span style="color:#880000">10</span>:<span style="color:#880000">43</span>上午 <span style="color:#880000">0</span>:<span style="color:#880000">00.02</span> nginx: master <span style="color:#0000ff">process</span> /usr/<span style="color:#0000ff">local</span>/opt/nginx/bin/nginx -g daemon off;
root <span style="color:#880000">2345</span> <span style="color:#880000">0.0</span> <span style="color:#880000">0.0</span> <span style="color:#880000">2432772</span> <span style="color:#880000">640</span> s000 S+ <span style="color:#880000">1</span>:<span style="color:#880000">01</span>下午 <span style="color:#880000">0</span>:<span style="color:#880000">00.00</span> grep nginx</code></span></span>
nginx的路径为:/usr/local/opt/nginx/bin/nginx
2.查看nginx配置文件路径
使用nginx的 -t 参数进行配置检查,即可知道实际调用的配置文件路径及是否调用有效。
<span style="background-color:rgba(0, 0, 0, 0)"><span style="color:#000000"><code>/usr/<span style="color:#0000ff">local</span>/opt/nginx/bin/nginx -t
nginx: <span style="color:#0000ff">the</span> configuration <span style="color:#a31515">file</span> /usr/<span style="color:#0000ff">local</span>/etc/nginx/nginx.conf syntax <span style="color:#0000ff">is</span> ok
nginx: configuration <span style="color:#a31515">file</span> /usr/<span style="color:#0000ff">local</span>/etc/nginx/nginx.conf test <span style="color:#0000ff">is</span> successful</code></span></span>
测试可知,nginx的配置文件路径为:/usr/local/etc/nginx/nginx.conf 且调用有效。
linux下如何查找nginx配置文件的位置,方法如下:
先找出nginx可执行文件的路径
1
|
ps -ef | grep nginx
|
返回
[root@localhost /data/nginx/logs 09:47:00&&23]#ps -ef | grep nginx
root 1734 1 0 Oct28 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
那么/usr/local/nginx/conf/nginx.conf就是配置文件了