# 6.1 Web server काय काम करतो?

Source: https://ravindrabagale.com/mr/aws/ch06-web-servers-nginx-and-apache/6-1-what-is-a-web-server.html
Language: mr (Marathi with English technical terms)

EC2 तयार आहे, पण website ला उत्तर देणारं software हवं. दुकान आहे पण shutter बंद असेल तर customer ला सेवा मिळत नाही, तशी कल्पना करा.

Web server HTTP साठी 80 आणि HTTPS साठी 443 सारख्या ports वर requests स्वीकारतो आणि HTML, images, CSS, JavaScript किंवा app ने तयार केलेला data परत देतो.

  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|
                                 +---------------------------------------+

तीन मुख्य कामं

Static files disk वरून serve करणं — HTML/CSS/JS/images.

Dynamic requests PHP-FPM, Node किंवा Gunicorn सारख्या backend कडे देऊन response आणणं — reverse proxy/FastCGI integration.

TLS, compression, caching, logs, अनेक virtual hosts, load balancing आणि rate limiting.

HTTP status codes

 | Code | अर्थ | नेहमीचं कारण

 | 200 | OK | Request यशस्वी

 | 301 / 302 | Permanent / temporary redirect | उदा. HTTP → HTTPS

 | 304 | Not Modified | Cached copy वापरता येते

 | 400 | Bad Request | Request malformed

 | 401 / 403 | Authentication लागते / access forbidden | Login किंवा permissions/index/SELinux

 | 404 | Not Found | चुकीचा path किंवा root

 | 500 | Internal Server Error | App/PHP मधला error

 | 502 | Bad Gateway | Upstream response/connection अडचण; app बंद किंवा चुकीचा socket/port

 | 503 | Unavailable | Overload किंवा maintenance

 | 504 | Gateway Timeout | Upstream कडून वेळेत response नाही

Lab

curl -I https://www.example.com आणि curl -I https://www.example.com/nahi-asa-page run करा. Status आणि उपलब्ध असल्यास Server header नोंदवा. दुसऱ्याला 404 येतो का प्रत्यक्ष तपासा; server चा configured व्यवहार वेगळा असू शकतो.

रवींद्र बागले यांची tip

502 आणि 504 वेगळे आहेत: upstream communication problem विरुद्ध timeout. 403 आला तर service उत्तर देतेय; permissions/index/config तपासा.
