[英]Locate the nginx.conf file my nginx is actually using
在安裝了兩個不同版本的 nginx 的客戶端服務器上工作。 我認為其中一個是用 brew package 管理器(它是一個 osx 盒子)安裝的,另一個似乎是用 nginx 打包安裝的 Makefile。我在服務器上搜索了所有 nginx.conf 文件,但沒有這些文件中的一部分定義了 nginx 在服務器上啟動時實際使用的參數。 我不知道的 nginx.conf 文件在哪里?
通過命令行運行nginx -t
將發出一個測試並將帶有文件路徑的輸出附加到配置文件(帶有錯誤或成功消息)。
nginx -t
和nginx -V
都會打印出默認的 nginx 配置文件路徑。
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
$ nginx -V
nginx version: nginx/1.11.1
built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.1k 8 Jan 2015
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf ...
如果需要,可以通過以下方式獲取配置文件:
$ nginx -V 2>&1 | grep -o '\-\-conf-path=\(.*conf\)' | cut -d '=' -f2
/etc/nginx/nginx.conf
即使您加載了其他一些配置文件,它們仍然會打印出默認值。
ps aux
會顯示當前加載的 nginx 配置文件。
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 11 0.0 0.2 31720 2212 ? Ss Jul23 0:00 nginx: master process nginx -c /app/nginx.conf
這樣您就可以通過例如以下方式實際獲取配置文件:
$ ps aux | grep "[c]onf" | awk '{print $(NF)}'
/app/nginx.conf
% ps -o args -C nginx
COMMAND
build/sbin/nginx -c ../test.conf
如果 nginx 在沒有-c
選項的情況下運行,那么您可以使用-V
選項找出設置為非標准值的配置參數。 其中對您來說最有趣的是:
--prefix=PATH set installation prefix
--sbin-path=PATH set nginx binary pathname
--conf-path=PATH set nginx.conf pathname
which nginx
會給你正在使用的 nginx 的路徑
編輯(2017 年 1 月 18 日)
感謝 Will Palmer 對此答案的評論,我添加了以下內容......
如果你已經通過 HomeBrew 之類的包管理器安裝了 nginx...
which nginx
可能不會給你正在使用的 nginx 的確切路徑。 但是,您可以使用
realpath $(which nginx)
正如@Daniel Li 所提到的
你可以通過他的方法獲取nginx的配置
或者你可以使用這個:
nginx -V
所有其他答案都很有用,但如果nginx
不在PATH
上,它們可能對您沒有幫助,因此您在嘗試運行nginx
時收到command not found
:
我在 Debian 7 Wheezy 上有 nginx 1.2.1, nginx
可執行文件不在PATH
上,所以我需要先找到它。 它已經在運行,所以使用ps aux | grep nginx
ps aux | grep nginx
我發現它位於/usr/sbin/nginx
,因此我需要運行/usr/sbin/nginx -t
。
如果要使用非默認配置文件(即不是/etc/nginx/nginx.conf
),請使用-c
參數運行它: /usr/sbin/nginx -c <path-to-configuration> -t
。
您可能還需要以root
身份運行它,否則 nginx 可能無權打開例如日志,因此該命令將失敗。
除了@Daniel Li 的回答,使用 Valet 安裝 nginx 也將使用 Velet 配置; 這可以在/usr/local/etc/nginx/valet/valet.conf
中找到。 nginx.conf
文件將導入此 Valet conf 文件。
您需要的設置可能在 Valet 文件中。
MacOS 中 nginx.conf 的路徑
/usr/local/etc/nginx/nginx.conf
您可以使用 mlocate 找到您的 nginx.conf 文件或任何文件
$ mlocate
<any file name or extention>
$ mlocate nginx.conf
所以你應該按照以下步驟進行:
$ sudo apt update
$ sudo apt install mlocate
或者
$ sudo apt-get update
$ sudo apt-get install mlocate
希望您的問題應該得到處理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.