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

Chapter 6: Web Servers — Nginx and Apache

6.1 What is a web server?

Friends, so far we have launched a server. But a server without a web server is like a shop with the shutter down — customers come but nobody serves them. Mauli Dairy's customers open the order page, but if nobody is there to answer, they see nothing. Let's understand what a web server really does.

A web server is software that listens on a port (80 for HTTP, 443 for HTTPS), accepts HTTP requests from browsers and returns responses — HTML pages, images, CSS, JavaScript files, or data produced by an application.

  Browser                         EC2 instance
 +--------+   GET /index.html    +---------------------------------------+
 |        | -------------------> | Web server (Nginx / Apache) :80       |
 |        |                      |   ├─ static file?  → read from disk   |
 |        | <------------------- |   └─ dynamic?      → pass to PHP /    |
 +--------+   200 OK + HTML      |                      Node / Python app|
                                 +---------------------------------------+

A web server does three main jobs:

  1. Serve static content — files that are the same for everyone (HTML, CSS, JS, images).
  2. Pass dynamic requests to an application (PHP-FPM, Node.js, Gunicorn) — called reverse proxying — and return its output.
  3. Handle cross-cutting concerns — TLS/HTTPS, compression, caching, logging, virtual hosts (many websites on one server), load balancing, rate limiting.

Common HTTP status codes

Code Meaning Typical cause
200 OK Success
301 / 302 Moved permanently / temporarily Redirect (e.g. HTTP → HTTPS)
304 Not modified Browser cache is fresh
400 Bad request Malformed request
401 / 403 Unauthorised / Forbidden Missing login / file permissions, no index file, SELinux
404 Not Found Wrong path or wrong document root
500 Internal server error Bug in app / PHP error
502 Bad Gateway Reverse-proxy target (app) is down or wrong port/socket
503 Service unavailable Overloaded or maintenance
504 Gateway timeout App took too long to respond

Ravindra Bagale's Tip

Many students mix up 502 and 504. Remember: 502 Bad Gateway means the app behind the proxy is down or the port/socket is wrong; 504 means the app took too long to reply. And if you get 403, check permissions and the index file first – the server is not down.

Lab

Chala, tumchya laptop var curl -I https://www.example.com chalva aani pahilya line madhla status code liha. Mag curl -I https://www.example.com/nahi-asa-page chalva aani 404 disato ka te bagha. Doni responses madhla Server: header pan liha.