Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGINX change config location

Tags:

nginx

I'm working on getting NGINX configured on a server and I've been able to get all of my files into /usr/local/nginx/html/. I've also created an nginx.conf file in /usr/local/nginx/conf. All it contains is:

server {
    root /usr/local/nginx/html;
    index index.html index.html;
}

I've been using /usr/local/ because that's the only thing I have permissions to write in. When I go to look at the site, I still get the Nginx index.html page with the message:

This is the default index.html page that is distributed with nginx on EPEL. It is located in /usr/share/nginx/html.

You should now put your content in a location of your choice and edit the root configuration directive in the nginx configuration file /etc/nginx/nginx.conf.

I guess my question is, how can I configure my nginx.conf file correctly so that it uses that conf file and pulls from the correction location for the site files?

like image 780
heatherthedev Avatar asked Oct 14 '14 02:10

heatherthedev


2 Answers

Whether you're starting nginx in a shell or using a daemon service (which is simply a wrapper around the command line api), the answer lies in the command line API.

As you learned, the default location nginx looks in for the configuration file is /etc/nginx/nginx.conf, but you can pass in an arbitrary path with the -c flag. E.g.:

$ nginx -c /usr/local/nginx/conf

A couple other notes:

  • I doubt there's any good reason to repeat "index.html" in your server block.
  • I would name your configuration file "nginx.conf" (you currently indicate that it's just named "conf"). It's the standard.
  • Familiarize yourself with another command line flag -t, which just checks to make sure your configuration file works. Run nginx -t every time after modifying your configuration file and it will spit out any syntax errors. To reload the configuration after changes, use nginx -s reload.
like image 63
Ryne Everett Avatar answered Dec 17 '22 23:12

Ryne Everett


This is how to compile nginx to look for the default conf in another directory:

./configure --conf-path=/etc/some/other/nginx.conf
make
make install
nginx

From the docs:

--conf-path=path — sets the name of an nginx.conf configuration file. If needs be, nginx can always be started with a different configuration file, by specifying it in the command-line parameter -c file. By default the file is named prefix/conf/nginx.conf.

like image 43
jmunsch Avatar answered Dec 17 '22 23:12

jmunsch