获取NGINX的默认配置文件位置

我在Intel架构的macOS 上使用 Homebrew 安装完 NGINX,发现不同硬件架构的 Homebrew 实际上将NGINX安装在不同的目录下,并且默认启动NGINX:

brew service restart nginx

并没有在命令行显示出NGINX使用哪个配置文件以及默认配置目录。

实际上,NGINX提供了参数 -V (大写的v),来输出当前的运行默认配置(即使没有参数):

获取NGINX默认配置
nginx -V

输出显示:

获取NGINX默认配置
nginx version: nginx/1.23.3
built by clang 14.0.0 (clang-1400.0.29.202)
built with OpenSSL 1.1.1s  1 Nov 2022
TLS SNI support enabled
configure arguments: --prefix=/usr/local/Cellar/nginx/1.23.3 --sbin-path=/usr/local/Cellar/nginx/1.23.3/bin/nginx --with-cc-opt='-I/usr/local/opt/pcre2/include -I/usr/local/opt/openssl@1.1/include' --with-ld-opt='-L/usr/local/opt/pcre2/lib -L/usr/local/opt/openssl@1.1/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-compat --with-debug --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-ipv6 --with-mail --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module

这样就能知道编译NGINX时候,传递的默认配置文件,这里的案例就是 /usr/local/etc/nginx/nginx.conf

不过 /usr/local/etc/nginx/nginx.conf 配置中没有指定文档目录,默认是 var/www ,也就是 /usr/local/var/www

参考