Locate the nginx.conf file my nginx is actually using

前端 未结 6 1471
南方客
南方客 2021-01-29 23:57

Working on a client\'s server where there are two different versions of nginx installed. I think one of them was installed with the brew package manager (its an osx box) and the

相关标签:
6条回答
  • 2021-01-30 00:13
    which nginx
    

    will give you the path of the nginx being used


    EDIT (2017-Jan-18)

    Thanks to Will Palmer's comment on this answer, I have added the following...

    If you've installed nginx via a package manager such as HomeBrew...

    which nginx
    

    may not give you the EXACT path to the nginx being used. You can however find it using

    realpath $(which nginx)
    

    and as mentioned by @Daniel Li

    you can get configuration of nginx via his method

    alternatively you can use this:

    nginx -V
    
    0 讨论(0)
  • 2021-01-30 00:23

    In addition to @Daniel Li's answer, the nginx installation with Valet would use the Velet configuration as well, this is found in "/usr/local/etc/nginx/valet/valet.conf". The nginx.conf file would have imported this Valet conf file. The settings you need may be in the Valet file.

    0 讨论(0)
  • 2021-01-30 00:25

    Both nginx -t and nginx -V would print out the default nginx config file path.

    $ 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 ...
    

    If you want, you can get the config file by:

    $ nginx -V 2>&1 | grep -o '\-\-conf-path=\(.*conf\)' | cut -d '=' -f2
    /etc/nginx/nginx.conf
    

    Even if you have loaded some other config file, they would still print out the default value.


    ps aux would show you the current loaded nginx config file.

    $ 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
    

    So that you could actually get the config file by for example:

    $ ps aux | grep "[c]onf" | awk '{print $(NF)}'
    /app/nginx.conf
    
    0 讨论(0)
  • 2021-01-30 00:25
    % ps -o args -C nginx
    COMMAND
    build/sbin/nginx -c ../test.conf
    

    If nginx was run without the -c option, then you can use the -V option to find out the configure arguments that were set to non-standard values. Among them the most interesting for you are:

    --prefix=PATH                      set installation prefix
    --sbin-path=PATH                   set nginx binary pathname
    --conf-path=PATH                   set nginx.conf pathname
    
    0 讨论(0)
  • 2021-01-30 00:33

    Running nginx -t through your commandline will issue out a test and append the output with the filepath to the configuration file (with either an error or success message).

    0 讨论(0)
  • 2021-01-30 00:40

    All other answers are useful but they may not help you in case nginx is not on PATH so you're getting command not found when trying to run nginx:

    I have nginx 1.2.1 on Debian 7 Wheezy, the nginx executable is not on PATH, so I needed to locate it first. It was already running, so using ps aux | grep nginx I have found out that it's located on /usr/sbin/nginx, therefore I needed to run /usr/sbin/nginx -t.

    If you want to use a non-default configuration file (i.e. not /etc/nginx/nginx.conf), run it with the -c parameter: /usr/sbin/nginx -c <path-to-configuration> -t.

    You may also need to run it as root, otherwise nginx may not have permissions to open for example logs, so the command would fail.

    0 讨论(0)
提交回复
热议问题