Chapter 6: Web Servers — Nginx and Apache
6.7 Understanding the configuration files
Friends, a config file is the set of instructions given to the web server. Today we only understand the big structure – which block does what – and the line-by-line reading happens in Chapter 8.
मित्रांनो, कॉन्फिग फाइल म्हणजे वेब सर्व्हरला दिलेल्या सूचना. आज फक्त मोठी रचना समजून घेऊ – कुठला ब्लॉक काय करतो – आणि लाइन बाय लाइन वाचन Chapter 8 मध्ये करू.
दोस्तों, कॉन्फ़िग फ़ाइल मतलब वेब सर्वर को दिए गए निर्देश. आज सिर्फ़ बड़ी रचना समझेंगे – कौन सा ब्लॉक क्या करता है – और लाइन बाय लाइन पढ़ाई Chapter 8 में करेंगे.
Nginx structure
# /etc/nginx/nginx.conf (simplified)
user nginx; # www-data on Ubuntu
worker_processes auto; # one worker per CPU core
events { worker_connections 1024; }
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
include /etc/nginx/conf.d/*.conf; # your site files
# Ubuntu also has: include /etc/nginx/sites-enabled/*;
server { # default server block
listen 80;
server_name _;
root /usr/share/nginx/html;
location / { try_files $uri $uri/ =404; }
}
}
Apache structure
# /etc/httpd/conf/httpd.conf (AL2023/CentOS, simplified)
Listen 80
User apache
Group apache
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Options Indexes FollowSymLinks
# change None to All to allow .htaccess files
AllowOverride None
Require all granted
</Directory>
ErrorLog "logs/error_log"
IncludeOptional conf.d/*.conf
Ravindra Bagale's Tip
Make sudo nginx -t && sudo service nginx reload a single habit – never restart blindly. In production, a restart with a broken config means downtime; a failed -t test costs you nothing. The same goes for apachectl configtest on Apache.
Ravindra Bagale's Tip – मराठी
sudo nginx -t && sudo service nginx reload ही एकच सवय बनवा – कधीच आंधळेपणाने restart करू नका. Production मध्ये तुटलेल्या config सोबत restart म्हणजे downtime; fail झालेली -t test तुम्हाला काहीच महाग पडत नाही. Apache साठी apachectl configtest तसंच.
Ravindra Bagale's Tip – हिंदी
sudo nginx -t && sudo service nginx reload को एक ही आदत बना लो – कभी भी आँख बंद करके restart मत करो. Production में टूटी config के साथ restart मतलब downtime; fail हुआ -t test तुम्हें कुछ भी महँगा नहीं पड़ता. Apache के लिए apachectl configtest भी ऐसे ही.
Ravindra Bagale's Tip
Many students write a comment at the end of a line in Apache config, like AllowOverride None # no htaccess – and Apache won't start. In Apache, always put a comment on its own line starting with #. In Nginx, on the other hand, don't forget the ; at the end of every directive.
Ravindra Bagale's Tip – मराठी
खूप students Apache config मध्ये line च्या शेवटी comment लिहितात, जसं AllowOverride None # no htaccess – आणि Apache start होत नाही. Apache मध्ये comment नेहमी वेगळ्या line वर # ने सुरू करायची. Nginx मध्ये उलट, प्रत्येक directive च्या शेवटी ; विसरू नका.
Ravindra Bagale's Tip – हिंदी
बहुत students Apache config में line के आखिर में comment लिखते हैं, जैसे AllowOverride None # no htaccess – और Apache start नहीं होता. Apache में comment हमेशा अलग line पर # से शुरू करो. Nginx में उल्टा, हर directive के आखिर में ; मत भूलो.
Going deeper
This section gives only the big picture. In Chapter 8 we read these files line by line and change the document root, ports and virtual hosts.
Lab
Chala, sudo grep -v '^\s*#' /etc/nginx/nginx.conf | grep -v '^$' chalva aani comments shivay config vacha. Tyat user, worker_processes, include aani root chya lines shodhun tyancha arth tumchya shabdat liha.