Skip to content
Log In Sign Up info@muvcloud.com

The Short Answer

sudo nginx -t

The output names the main file it tested, normally /etc/nginx/nginx.conf. That file sets global options and includes the rest: the sites, the modules, and shared snippets.

Debian and Ubuntu Layout

PathRole
nginx.confMain file
sites-available/One file per site
sites-enabled/Links to active sites
conf.d/Extra settings, *.conf
snippets/Reusable pieces
modules-enabled/Dynamic modules
mime.typesFile types

All paths are under /etc/nginx/. The shipped site is sites-available/default, enabled by a link of the same name in sites-enabled. The snippets folder holds fastcgi-php.conf, which PHP server blocks include. How the site files work is in Nginx server blocks.

AlmaLinux and Rocky Linux Layout

  • /etc/nginx/nginx.conf: the main file, which also contains the server block for the default page. It has no default_server marker and comes after the conf.d include.
  • /etc/nginx/conf.d/: one .conf file per site; there are no sites folders.
  • /etc/nginx/default.d/: files included inside that server block.
  • /usr/share/nginx/html: the default web root.

Installing the php-fpm package adds conf.d/php-fpm.conf, which defines an upstream named php-fpm for the socket /run/php-fpm/www.sock, and default.d/php.conf, which passes PHP files of the default site to it.

Packages from nginx.org

If Nginx was installed from the Nginx project's own repository rather than the distribution's, the layout is the same on every system: no sites folders, a sample site in /etc/nginx/conf.d/default.conf, and the nginx user even on Debian and Ubuntu. Check which package you have with apt policy nginx or dnf info nginx.

Find the Paths Nginx Was Built With

nginx -V 2>&1 | tr ' ' '\n' | grep -E 'prefix|conf-path|log-path'

nginx -V prints the build options to standard error, which is why the output is redirected. --conf-path is the default main file and --prefix the base for relative paths. If Nginx was started with -c and another file, ps -o cmd -C nginx shows it on the master process line.

See the Whole Configuration

sudo nginx -T | less
sudo nginx -T | grep -n server_name

nginx -T tests the configuration and prints every file it read, each one introduced by a comment line with its path. It is the fastest way to find which file sets a directive, and the output to share when you ask for help. Remove keys and passwords from it first.

Include Order and Contexts

The configuration is nested: the main context holds the events and http blocks, http holds server blocks, and each server holds location blocks. On Debian and Ubuntu the http block ends with:

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

Files that match a wildcard are read in alphabetical order. Order matters when no block is marked default_server, because the first server block for a port then becomes the default. Note the second line: it includes every file in sites-enabled, whatever its name. On AlmaLinux and Rocky Linux the conf.d include comes before the shipped server block, so the first site file there that listens on a port becomes its default.

Edit Safely

  • Back up outside the include folders: a copy named example.com.bak in sites-enabled is loaded as a second site. Keep copies in your home folder or /root; see the cp command.
  • Test, then reload: sudo nginx -t, then sudo systemctl reload nginx. A failed test leaves the running server untouched, while a restart with a broken file stops the site. See how to start, stop, and reload Nginx.
  • Log settings are covered in Nginx logs.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations