NGINX changes configuration position

advertisements

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?


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.