rgb
rgb

Reputation: 3294

Locate the nginx.conf file my nginx is actually using

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?

Upvotes: 212

Views: 285695

Answers (10)

Aakash Handa
Aakash Handa

Reputation: 1307

Nginx.conf location in Mac /usr/local/etc/nginx/nginx.conf

Upvotes: 0

tuwilof
tuwilof

Reputation: 587

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

Upvotes: 12

CHAVDA MEET
CHAVDA MEET

Reputation: 935

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.

Upvotes: 1

Olusola Omosola
Olusola Omosola

Reputation: 905

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.

Upvotes: 1

Aakash Handa
Aakash Handa

Reputation: 1307

Path of nginx.conf in MacOS

/usr/local/etc/nginx/nginx.conf

Upvotes: 0

David Ferenczy Rogožan
David Ferenczy Rogožan

Reputation: 25401

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.

Upvotes: 7

Craig Wayne
Craig Wayne

Reputation: 5060

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

Upvotes: 14

Jing Li
Jing Li

Reputation: 15116

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

Upvotes: 82

VBart
VBart

Reputation: 15110

% 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

Upvotes: 36

Daniel Li
Daniel Li

Reputation: 15379

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

Upvotes: 385

Related Questions