X
Popular Searches

How to Find Your Nginx Configuration Folder

NGINX Logo
NGINX

Nginx uses text-based configuration files to govern its behavior. It usually defaults to /etc/nginx/, and contains a few different config files, though the location may vary depending on your install.

The Usual Locations

The default location for the nginx configuration folder is:

/etc/nginx/

This location likely is the default for all normal installs. If you installed nginx from your distro’s package manager, it’s likely located here.

Within this directory you have a few files, regardless of where the main folder is located on your drive:

  • nginx.conf, which is nginx’s primary configuration file.
  • sites-available/, a directory that usually contains different configuration files for each individual domain name your server hosts. For example, sites-available/example.com may contain a block with ServerName example.com, though you can use these files for anything.
  • sites-enabled/, a directory that contains symlinks to the configuration files in sites-available. It essentially acts as a toggle, and enables you to turn sites on and off by symlinking different files.

If you don’t have the folder at /etc/nginx/, your installation may have created it elsewhere, which is likely if you’ve compiled it yourself. In this scenario, it’s probably installed to the /usr/local/ folder, in one of the following root directories:

  •  /usr/local/nginx/, the most likely scenario if you’ve compiled from source
  •  /usr/local/nginx/conf/
  • /usr/local/etc/nginx/

If it’s not here, it’s probably operating in a containerized environment, or something has gone wrong during installation. If so, you need to locate it manually.

How to Find The Config Folder Manually

Nginx provides a command for testing configuration file syntax before restarting and applying changes. You should run it whenever you make changes to prevent downtime due to crashes, but you can also use it to find the location of the file nginx is using.

The command is simply:

nginx -t

While it tests your configuration file, it also echos out the full path to it as well, regardless of where it’s installed:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If this function doesn’t run, you don’t have nginx installed in the first place (or it’s not on your system PATH).

Document Root Locations

You can change the document root to anything you want, so it doesn’t matter as much as the config locations. The default location should be:

  • /var/www/html/ on Debian-based systems like Ubuntu
  •  /usr/share/nginx/html/ on RHEL-based systems like CentOS

Either way, the document root is hardcoded in the configuration files, so you can find it from there.

Anthony Heddings Anthony Heddings
Anthony Heddings is the resident cloud engineer for LifeSavvy Media, a technical writer, programmer, and an expert at Amazon's AWS platform. He's written hundreds of articles for How-To Geek and CloudSavvy IT that have been read millions of times. Read Full Bio »

The above article may contain affiliate links, which help support CloudSavvy IT.