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

Chapter 6: Web Servers — Nginx and Apache

6.8 Everyday management commands

Friends, once the web server is installed, the daily work is the same: test, reload, look at the logs. This table will be used every day on the Amul-style dairy server – once it is in your hands, troubleshooting becomes fast.

Task Nginx Apache (AL2023/CentOS) Apache (Ubuntu)
Test config sudo nginx -t sudo apachectl configtest sudo apache2ctl configtest
Reload (no downtime) sudo service nginx reload sudo service httpd reload sudo service apache2 reload
Restart sudo service nginx restart sudo service httpd restart sudo service apache2 restart
Error log sudo tail -​f /​var/​log/​nginx/​error.​log sudo tail -​f /​var/​log/​httpd/​error_​log sudo tail -​f /​var/​log/​apache2/​error.​log
Access log /​var/​log/​nginx/​access.​log /​var/​log/​httpd/​access_​log /​var/​log/​apache2/​access.​log
Version nginx -v httpd -v apache2 -v
Loaded modules nginx -V httpd -M apache2ctl -M

Always test before reload

Use sudo nginx -t && sudo service nginx reload. The reload runs only if the test passes, so a typo never takes your site down.

Ravindra Bagale's Tip

Many students Google an error right away but never open the error log. First look at sudo tail -n 20 /var/log/nginx/error.log (Apache: /var/log/httpd/error_log) – most of the time the file name and line number are right there.

Lab

Chala, Nginx config madhe muddam ek ; kadha aani sudo nginx -t chalva – error kuthli file aani line sangto te liha. Mag ; parat taka, sudo nginx -t && sudo service nginx reload chalva aani sudo tail -n 5 /var/log/nginx/error.log bagha.

The daily routine, explained step by step

  1. Test the config. A typo is caught here, not by your users.
  2. Reload. New settings apply and existing visitors stay connected.
  3. Check with curl -I from the server itself.
  4. Read the logs if anything looks wrong.
Safe routineEditTest (-t)Reloadcurl -ILogs
The same five steps for every change, on every web server.

The same routine on other servers you will meet

nginx and Apache are covered in the table above. Real servers often run other programs too. Here is the "is it healthy?" command for each.

nginx

Event-driven web server and reverse proxy.

sudo nginx -t && sudo systemctl reload nginx

What you see:

nginx: configuration file /etc/nginx/nginx.conf test is successful
Apache httpd (Amazon Linux, CentOS) / apache2 (Ubuntu)

Process- and thread-based server with many modules and .htaccess support.

sudo apachectl configtest && sudo systemctl reload httpd

What you see:

Syntax OK
Tomcat (Java apps)

Runs Java web apps (WAR files) and Spring Boot apps packaged as WARs. Usually sits behind nginx or Apache on 8080.

sudo systemctl status tomcat
curl -I http://127.0.0.1:8080

What you see:

HTTP/1.1 200
Kestrel (ASP.NET Core)

The built-in .NET web server. In production it usually sits behind nginx, Apache or IIS.

curl -I http://127.0.0.1:5000

What you see:

Server: Kestrel
Gunicorn / Uvicorn (Python)

Gunicorn serves WSGI apps (Flask, Django). Uvicorn serves ASGI apps (FastAPI). Both sit behind nginx.

curl -I http://127.0.0.1:8000

What you see:

server: uvicorn
Node.js (Express) with PM2

Node is its own HTTP server. PM2 keeps it running.

pm2 status

What you see:

│ app │ online │
PHP-FPM

Runs PHP for nginx (or Apache) over FastCGI on a socket or port 9000.

sudo systemctl status php-fpm

What you see:

Active: active (running)

Summary

ServerTest / checkLogs
nginxnginx -t/var/log/nginx/
Apacheapachectl configtest/var/log/httpd or apache2
Tomcatcurl :8080logs/catalina.out
Kestrelcurl :5000journalctl -u app
Gunicorn/Uvicorncurl :8000journalctl -u app
Node/PM2pm2 statuspm2 logs
PHP-FPMphp-fpm -t/var/log/php-fpm/

Real examples

Indian company (sample): suppose we are a junior engineer at a Nykaa-style shop during a sale. A colleague adds a redirect and forgets a semicolon. Because the deploy script runs nginx -t && reload, the reload is skipped, the site stays up and the error shows the exact line. Global: the nginx and Apache documentation both recommend testing configuration before reloading. Everyday: a pilot runs a checklist before take-off, every single time.

Recap

  • Test, reload, check, read logs.
  • Every server type has its own health command, so learn the ones for your stack.