nginx的配置放在nginx.conf文件中,一般我们可以使用以下命令查看服务器中存在的nginx.conf文件。
<span style="color:#000000"><code>locate nginx.conf
/usr/local/etc/nginx/nginx.conf
/usr/local/etc/nginx/nginx.conf.default
<span style="color:#000088 !important">...</span></code></span>
如果服务器中存在多个nginx.conf文件,我们并不知道实际上调用的是哪个配置文件,因此我们必须找到实际调用的配置文件才能进行修改。
查看nginx实际调用的配置文件
1.查看nginx路径
<span style="color:#000000"><code>ps aux|grep nginx
root <span style="color:#006666 !important">352</span> <span style="color:#006666 !important">0.0</span> <span style="color:#006666 !important">0.0</span> <span style="color:#006666 !important">2468624</span> <span style="color:#006666 !important">924</span> ?? S <span style="color:#006666 !important">10</span>:<span style="color:#006666 !important">43</span>上午 <span style="color:#006666 !important">0</span>:<span style="color:#006666 !important">00.08</span> nginx: worker <span style="color:#4f4f4f !important">process</span>
root <span style="color:#006666 !important">232</span> <span style="color:#006666 !important">0.0</span> <span style="color:#006666 !important">0.0</span> <span style="color:#006666 !important">2459408</span> <span style="color:#006666 !important">532</span> ?? S <span style="color:#006666 !important">10</span>:<span style="color:#006666 !important">43</span>上午 <span style="color:#006666 !important">0</span>:<span style="color:#006666 !important">00.02</span> nginx: master <span style="color:#4f4f4f !important">process</span> /usr/<span style="color:#4f4f4f !important">local</span>/opt/nginx/bin/nginx -g daemon off;
root <span style="color:#006666 !important">2345</span> <span style="color:#006666 !important">0.0</span> <span style="color:#006666 !important">0.0</span> <span style="color:#006666 !important">2432772</span> <span style="color:#006666 !important">640</span> s000 S+ <span style="color:#006666 !important">1</span>:<span style="color:#006666 !important">01</span>下午 <span style="color:#006666 !important">0</span>:<span style="color:#006666 !important">00.00</span> grep nginx</code></span>
nginx的路径为:/usr/local/opt/nginx/bin/nginx
2.查看nginx配置文件路径
使用nginx的 -t 参数进行配置检查,即可知道实际调用的配置文件路径及是否调用有效。
<span style="color:#000000"><code>/usr/<span style="color:#000088 !important">local</span>/opt/nginx/bin/nginx -t
nginx: <span style="color:#000088 !important">the</span> configuration <span style="color:#d19a66">file</span> /usr/<span style="color:#000088 !important">local</span>/etc/nginx/nginx.conf syntax <span style="color:#000088 !important">is</span> ok
nginx: configuration <span style="color:#d19a66">file</span> /usr/<span style="color:#000088 !important">local</span>/etc/nginx/nginx.conf test <span style="color:#000088 !important">is</span> successful</code></span>
测试可知,nginx的配置文件路径为:/usr/local/etc/nginx/nginx.conf 且调用有效。