Configuration Files Structure
Nginx Configuration Files
Nginx Configuration File’s Structure and Best Practices
All Nginx configuration files are located in the
/etc/nginxdirectory.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-availabledirectory. The configuration files found in this directory are not used by Nginx unless they are linked to the/etc/nginx/sites-enableddirectory.To activate a server block, you need to create a symlink (a pointer) from the configuration file sites in a
sites-availabledirectory to thesites-enableddirectory.It is recommended to follow the standard naming convention. For example, if your domain name is
mydomain.comthen your configuration file should be named/etc/nginx/sites-available/mydomain.com.conf
Log Files
Nginx log files (
access.loganderror.log) are located in the/var/log/nginxdirectory. It is recommended to have a differentaccessanderrorlog 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/snippetsdirectory 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