Chapter 8: Configuring Nginx and Apache
8.1 Where the configuration lives
Friends, before changing a config you must know where the file is. The table below tells you everything in a few columns – the main file, your site's file, how a site is enabled and where the logs are.
मित्रांनो, कॉन्फिग बदलायच्या आधी फाइल कुठे आहे हे माहिती पाहिजे. खालचा टेबल काही कॉलम्समध्ये सगळं सांगतो – मेन फाइल, तुमच्या साइटची फाइल, साइट enable कशी होते आणि लॉग्स कुठे.
दोस्तों, कॉन्फ़िग बदलने से पहले फ़ाइल कहाँ है ये पता होना चाहिए. नीचे वाला टेबल कुछ कॉलम्स में सब बताता है – मेन फ़ाइल, आपकी साइट की फ़ाइल, साइट enable कैसे होती है और लॉग्स कहाँ हैं.
| 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. Keep each site in its own small file in conf.d or sites-available. Then you can copy a site to another server, disable a site by renaming one file, and an OS update won't overwrite your work. A really clean setup.
Ravindra Bagale's Tip – मराठी
Website साठी main file (nginx.conf, httpd.conf, apache2.conf) कधीच edit करू नका. प्रत्येक site स्वतःच्या छोट्या file मध्ये conf.d किंवा sites-available मध्ये ठेवा. मग एक site दुसऱ्या server वर copy करता येते, एक file rename करून site बंद करता येते, आणि OS update तुमचं काम overwrite करत नाही. एकदम clean setup.
Ravindra Bagale's Tip – हिंदी
Website के लिए main file (nginx.conf, httpd.conf, apache2.conf) कभी edit मत करो. हर site अपनी छोटी file में conf.d या sites-available में रखो. फिर एक site दूसरे server पर copy कर सकते हो, एक file rename करके site बंद कर सकते हो, और 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.
Ravindra Bagale's Tip
Many students keep a backup like mysite.conf.bak.conf or mysite-old.conf right inside conf.d – then the same site loads twice and you get a conflicting server name warning. A backup name must not end in .conf: mysite.conf.bak.
Ravindra Bagale's Tip – मराठी
खूप students backup mysite.conf.bak.conf किंवा mysite-old.conf असा conf.d मध्येच ठेवतात – मग तीच site दोन वेळा load होते आणि conflicting server name warning येतं. Backup चं नाव .conf ने संपू नये: mysite.conf.bak.
Ravindra Bagale's Tip – हिंदी
बहुत students backup mysite.conf.bak.conf या mysite-old.conf जैसा conf.d में ही रखते हैं – फिर वही site दो बार load होती है और conflicting server name warning आती है. Backup का नाम .conf पर खत्म नहीं होना चाहिए: mysite.conf.bak.
Lab
Chala, tumchya server var sudo nginx -T | grep -E "server_name|root|listen" (Apache: sudo apachectl -S) chalva aani kharach kiti sites load aahet te liha. Mag tumchya site file cha .bak backup ghya aani ls /etc/nginx/conf.d/ madhe to .conf ne sampat nahi na te check kara.