Chapter 6: Web Servers — Nginx and Apache
6.7 Understanding the configuration files
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. Same for Apache with apachectl configtest.
Ravindra Bagale's Tip – मराठी
sudo nginx -t && sudo service nginx reload ही एकच सवय लावा — कधीही डोळे झाकून restart करू नका. Production मध्ये बिघडलेल्या config सोबत restart म्हणजे downtime; पण -t test fail झाला तर तुमचं काहीच नुकसान होत नाही. Apache साठीही तसंच, apachectl configtest वापरा.
Ravindra Bagale's Tip – हिंदी
sudo nginx -t && sudo service nginx reload को एक ही आदत बना लो — कभी भी आँख बंद करके restart मत करो. Production में टूटे config के साथ restart का मतलब downtime; जबकि -t test fail होने से तुम्हारा कुछ नहीं बिगड़ता. Apache के लिए भी यही, apachectl configtest से.
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.