Ravindra BagaleCourses & study guides

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.

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.