【问题标题】:Locate the nginx.conf file my nginx is actually using找到我的 nginx 实际使用的 nginx.conf 文件
【发布时间】:2013-11-23 11:20:22
【问题描述】:

在安装了两个不同版本的 nginx 的客户端服务器上工作。我认为其中一个是用 brew 包管理器(它是一个 osx 盒子)安装的,另一个似乎是用 nginx 打包的 Makefile 编译和安装的。我搜索了服务器上的所有 nginx.conf 文件,但是这些文件都没有定义我在服务器上启动 nginx 时实际使用的参数。我不知道的 nginx.conf 文件在哪里?

【问题讨论】:

    标签: macos nginx sysadmin


    【解决方案1】:

    通过命令行运行nginx -t 将发出一个测试并将带有文件路径的输出附加到配置文件(带有错误或成功消息)。

    【讨论】:

      【解决方案2】:

      nginx -tnginx -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
      

      【讨论】:

        【解决方案3】:
        % 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
        

        【讨论】:

        • 我尝试运行这些命令,但它们对我不起作用.. 第二个答案有效
        【解决方案4】:
        which nginx
        

        会给你正在使用的 nginx 的路径


        编辑(2017 年 1 月 18 日)

        感谢 Will Palmer 对此答案的评论,我添加了以下内容...

        如果你通过 HomeBrew 等包管理器安装了 nginx...

        which nginx
        

        可能不会为您提供正在使用的 nginx 的 EXACT 路径。但是,您可以使用

        找到它
        realpath $(which nginx)
        

        正如@Daniel Li 所提到的

        你可以通过他的方法获取nginx的配置

        或者你可以使用这个:

        nginx -V
        

        【讨论】:

        • "which" 适用于大多数基于 Unix 的系统。我只是在 Ubuntu 上输入它以确保我没有失去理智。
        • 哦,哇,我的立场是正确的。马上修改答案。谢谢
        • which nginx 仅显示当前用户的 nginx 的 default 路径(甚至不显示当前用户 - 当前 shell)。它绝对没有显示 nginx“正在使用”的路径。
        【解决方案5】:

        所有其他答案都很有用,但如果 nginx 不在 PATH 上,它们可能对您没有帮助,因此您在尝试运行 nginx 时会收到 command not found::: p>

        我在 Debian 7 Wheezy 上有 nginx 1.2.1,nginx 可执行文件不在 PATH 上,所以我需要先找到它。它已经在运行,所以使用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可能没有权限打开例如日志,所以命令会失败。

        【讨论】:

          【解决方案6】:

          除了@Daniel Li 的回答,使用 Valet 安装 nginx 也将使用 Velet 配置,这可以在“/usr/local/etc/nginx/valet/valet.conf”中找到。 nginx.conf 文件将导入此 Valet conf 文件。您需要的设置可能在 Valet 文件中。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2017-05-28
            • 1970-01-01
            • 1970-01-01
            • 2019-07-23
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2014-04-04
            相关资源
            最近更新 更多