Configuration Files Structure
Nginx Configuration Files
Nginx Configuration File’s Structure and Best Practices
All Nginx configuration files are located in the
/etc/nginx
directory.The main Nginx configuration file is
/etc/nginx/nginx.conf
Sites
To make Nginx configuration easier to maintain, it is recommended to create a separate configuration file for each domain. You can have as many server block files as you need.
Nginx server block files are stored in
/etc/nginx/sites-available
directory. The configuration files found in this directory are not used by Nginx unless they are linked to the/etc/nginx/sites-enabled
directory.To activate a server block, you need to create a symlink (a pointer) from the configuration file sites in a
sites-available
directory to thesites-enabled
directory.It is recommended to follow the standard naming convention. For example, if your domain name is
mydomain.com
then your configuration file should be named/etc/nginx/sites-available/mydomain.com.conf
Log Files
Nginx log files (
access.log
anderror.log
) are located in the/var/log/nginx
directory. It is recommended to have a differentaccess
anderror
log files for each server block.
Webroot
You can set your domain document root directory to any location you want. The most common locations for webroot include:
/home/<user_name>/<site_name>
/var/www/<site_name>
/var/www/html/<site_name>
/opt/<site_name>
Snippets
The
/etc/nginx/snippets
directory contains configuration snippets that can be included in the server block files. If you use repeatable configuration segments, then you can refactor those segments into snippets and include the snippet file to the server blocks.
Last updated