Ravindra BagaleCourses & study guides

Chapter 8: Configuring Nginx and Apache

8.1 Where the configuration lives

Item Nginx (AL2023 / CentOS) Nginx (Ubuntu) Apache (AL2023 / CentOS) Apache (Ubuntu)
Main file /​etc/​nginx/​nginx.​conf /​etc/​nginx/​nginx.​conf /​etc/​httpd/​conf/​httpd.​conf /​etc/​apache2/​apache2.​conf
Your site files /​etc/​nginx/​conf.​d/*.​conf /​etc/​nginx/​sites-​available/ /​etc/​httpd/​conf.​d/*.​conf /​etc/​apache2/​sites-​available/*.​conf
How a site is enabled Any .conf in conf.d is loaded Symlink into sites-enabled/ Any .conf in conf.d is loaded sudo a2ensite name.​conf
Default site server block inside nginx.conf sites-​enabled/​default welcome.conf + /var/www/html 000-default.conf
Default web root /​usr/​share/​nginx/​html /var/www/html /var/www/html /var/www/html
Ports file inside each server inside each server Listen in httpd.conf /​etc/​apache2/​ports.​conf
Worker user nginx www-data apache www-data
Logs /var/log/nginx/ /var/log/nginx/ /var/log/httpd/ /​var/​log/​apache2/
Test config sudo nginx -t sudo nginx -t sudo apachectl configtest sudo apache2ctl configtest
Show loaded sites sudo nginx -T sudo nginx -T sudo httpd -S sudo apache2ctl -​S

Ravindra Bagale's Tip

Never edit the main file (nginx.conf, httpd.conf, apache2.conf) for a website. Put each site in its own small file in conf.d or sites-available. Then you can copy one site to another server, disable a site by renaming one file, and an OS update won't overwrite your work. A perfectly clean setup.

Always back up before editing

sudo cp /etc/nginx/conf.d/mysite.conf /etc/nginx/conf.d/mysite.conf.bak takes one second. On AL2023/CentOS, a backup must not end in .conf, or it will be loaded as a second site. That's why we name it .bak.