196

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 other seems to have been compiled and installed with the nginx packaged Makefile. I searched for all of the nginx.conf files on the server, but none of these files define the parameters that nginx is actually using when I start it on the server. Where is the nginx.conf file that I'm unaware of?

Daniel Li
  • 14,976
  • 6
  • 43
  • 60
rgb
  • 3,144
  • 3
  • 17
  • 26

9 Answers9

346

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

Daniel Li
  • 14,976
  • 6
  • 43
  • 60
69

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
Jing Li
  • 14,547
  • 7
  • 57
  • 69
35
% 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
Daniel Li
  • 14,976
  • 6
  • 43
  • 60
VBart
  • 14,714
  • 4
  • 45
  • 49
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
Craig Wayne
  • 4,499
  • 4
  • 35
  • 50
  • 1
    "which" works on most Unix based systems. I just typed it on Ubuntu to make sure I hadn't lost my mind. – tqwhite May 25 '16 at 15:28
  • 1
    oh wow, i stand corrected. modifying the answer right away. thanks – Craig Wayne May 25 '16 at 15:45
  • 3
    `which nginx` only shows the *default* path for nginx for the current user (not even the current user - the current *shell*). It definitely does not show the path for which nginx "is being used". – Will Palmer Nov 08 '16 at 10:06
6

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.

David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
1

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.

J. Scott Elblein
  • 4,013
  • 15
  • 58
  • 94
Olusola Omosola
  • 847
  • 9
  • 9
1

Path of nginx.conf in MacOS

/usr/local/etc/nginx/nginx.conf
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Aakash Handa
  • 1,215
  • 11
  • 18
1

Let's save a time

you can find your nginx.conf file or any file using mlocate

$ mlocate <any file name or extention>

$ mlocate nginx.conf

If mlocate package not installed or ERROR: mlocate has no installation candidate

So you should proceed as follows:

$ sudo apt update

$ sudo apt install mlocate

or

$ sudo apt-get update

$ sudo apt-get install mlocate

Hopefully, your issue should be handled.

CHAVDA MEET
  • 777
  • 8
  • 14
1

for me

$ nginx -t                              
nginx: the configuration file /opt/homebrew/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /opt/homebrew/etc/nginx/nginx.conf test is successful

$ vim /opt/homebrew/etc/nginx/nginx.conf
tuwilof
  • 351
  • 3
  • 6