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.
मित्रांनो, वेब सर्व्हर इन्स्टॉल झाला की रोज हेच काम: टेस्ट, reload, लॉग्स बघणं. हा टेबल Amul-स्टाइल डेअरीच्या सर्व्हरवर रोज वापरला जाईल – एकदा हातात बसला की ट्रबलशूटिंग फास्ट होतं.
दोस्तों, वेब सर्वर इंस्टॉल हो गया तो रोज़ यही काम: टेस्ट, reload, लॉग्स देखना. ये टेबल Amul-स्टाइल डेयरी के सर्वर पर रोज़ इस्तेमाल होगा – एक बार हाथ में बैठ गया तो ट्रबलशूटिंग फ़ास्ट हो जाती है.
| 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.
Ravindra Bagale's Tip – मराठी
खूप students error आला की लगेच Google करतात, पण error log उघडत नाहीत. आधी sudo tail -n 20 /var/log/nginx/error.log (Apache: /var/log/httpd/error_log) बघा – बहुतेक वेळा file चं नाव आणि line number तिथेच मिळतं.
Ravindra Bagale's Tip – हिंदी
बहुत students error आते ही तुरंत Google करते हैं, पर error log नहीं खोलते. पहले sudo tail -n 20 /var/log/nginx/error.log (Apache: /var/log/httpd/error_log) देखो – ज़्यादातर बार file का नाम और line number वहीं मिल जाता है.
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
- Test the config. A typo is caught here, not by your users.
- Reload. New settings apply and existing visitors stay connected.
- Check with
curl -Ifrom the server itself. - Read the logs if anything looks wrong.
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 nginxWhat you see:
nginx: configuration file /etc/nginx/nginx.conf test is successfulApache httpd (Amazon Linux, CentOS) / apache2 (Ubuntu)
Process- and thread-based server with many modules and .htaccess support.
sudo apachectl configtest && sudo systemctl reload httpdWhat you see:
Syntax OKTomcat (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:8080What you see:
HTTP/1.1 200Kestrel (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:5000What you see:
Server: KestrelGunicorn / Uvicorn (Python)
Gunicorn serves WSGI apps (Flask, Django). Uvicorn serves ASGI apps (FastAPI). Both sit behind nginx.
curl -I http://127.0.0.1:8000What you see:
server: uvicornNode.js (Express) with PM2
Node is its own HTTP server. PM2 keeps it running.
pm2 statusWhat you see:
│ app │ online │PHP-FPM
Runs PHP for nginx (or Apache) over FastCGI on a socket or port 9000.
sudo systemctl status php-fpmWhat you see:
Active: active (running)Summary
| Server | Test / check | Logs |
|---|---|---|
| nginx | nginx -t | /var/log/nginx/ |
| Apache | apachectl configtest | /var/log/httpd or apache2 |
| Tomcat | curl :8080 | logs/catalina.out |
| Kestrel | curl :5000 | journalctl -u app |
| Gunicorn/Uvicorn | curl :8000 | journalctl -u app |
| Node/PM2 | pm2 status | pm2 logs |
| PHP-FPM | php-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.