Ravindra BagaleCourses & study guides मराठी Track your progress

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.

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

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.

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.