Nginx
CLI References
nginx -V |
(uppercase V) to see all the nginx configuration settings.- --conf-path= The nginx config file location.- --prefix= The directory prefix where nginx looks for server files. |
sudo nginx -t |
Test the Nginx configuration files for syntax errors. Parses all the Nginx configuration files but does not apply them or restart the server. This allows you to validate your changes safely before making them live. It also performs a comprehensive syntax check of all configuration files that are included or referenced by your main nginx.conf file (or by another file that is itself included). |
sudo systemctl reload nginx |
Reload config changes without a restart. This is a "graceful" reload of the Nginx web server. It instructs the system's systemd service manager to send a signal to the Nginx process that tells it to reload its configuration files without stopping and restarting the entire service. Using reload is preferable to restart because it allows Nginx to apply the new configuration without killing the master process, ensuring zero downtime for users. |
Config Files
The main nginx.conf file typically contains include directives that point to other directories or specific files.
# Include files in the /etc/nginx/conf.d/ directory.
# This is where you might place server blocks for individual domains.
include /etc/nginx/conf.d/*.conf;
# Include files in the /etc/nginx/sites-enabled/ directory.
# This is common on Debian/Ubuntu systems for managing virtual hosts.
include /etc/nginx/sites-enabled/*;
Changing Config Files
The professional config change workflow looks like this:
- Make changes to an Nginx configuration file (e.g., /etc/nginx/sites-available/example.com).
- Run the test command
sudo nginx -tto ensure your changes are valid. - If the test passes, gracefully reload Nginx with
sudo systemctl reload nginxto apply the new configuration.