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.
Ravindra Bagale's Tip – मराठी
Website साठी main file (nginx.conf, httpd.conf, apache2.conf) कधीच edit करू नका. प्रत्येक site conf.d किंवा sites-available मध्ये तिच्या स्वतःच्या छोट्या file मध्ये ठेवा. मग एखादी site दुसऱ्या server वर copy करता येते, एक file rename करून site disable करता येते, आणि OS update तुमचं काम overwrite करत नाही. एकदम clean setup.
Ravindra Bagale's Tip – हिंदी
Website के लिए main file (nginx.conf, httpd.conf, apache2.conf) कभी edit मत करो. हर site को conf.d या sites-available में उसकी अपनी छोटी file में रखो. फिर किसी site को दूसरे server पर copy कर सकते हो, एक file rename करके site disable कर सकते हो, और OS update तुम्हारा काम overwrite नहीं करेगा. एकदम 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.