Ravindra BagaleCourses & study guides

7. Apache and Nginx: Install and Understand

7.1 What a Web Server Does: Nginx vs Apache

Web server ek program aahe jo port 80/443 var request aiktoy, Host header aani URL baghun yogya file kiwa application cha response parat pathavto. Class madhe vicharla jata "Sir, konta better?" – dogha uttam aahet, use case var avalamba.

Feature Nginx Apache (httpd / apache2)
Architecture Event-driven, asynchronous; few worker processes handle thousands of connections Process/thread per connection (MPMs: prefork, worker, event)
Static content Extremely fast, low memory Fast, but uses more memory under heavy load
Dynamic content (PHP) Via external PHP-FPM (FastCGI) Via mod_php (embedded) or PHP-FPM
Configuration Central config files; server {} blocks Central config + per-directory .htaccess files
.htaccess support No (faster, but less flexible for shared hosting) Yes (WordPress pretty links, shared hosting)
Reverse proxy / load balancer Excellent, built in Good (mod_proxy, mod_proxy_balancer)
Modules Compiled in or dynamic modules Huge set of dynamically loadable modules
Virtual hosts server { server_​name ... } <VirtualHost *:​80> ServerName ... </​VirtualHost>
Typical use Reverse proxy for Node/Python, static sites, high traffic LAMP apps, WordPress, legacy apps, shared hosting

Which should I choose?

For static sites and as a reverse proxy in front of Node.js/Python apps, Nginx is the default modern choice. For PHP applications that rely on .htaccess (many WordPress plugins), Apache is the easiest. Only one of them can listen on port 80 at a time — stop one before starting the other on the same server.

Why this matters for security

The web server is the front door of every web application. Its banner (Server: nginx/1.24.0) tells attackers which version to look up in exploit databases; directory listing exposes files; a forgotten test page or backup file leaks information. Scanners like Nikto (Part 10) check exactly these things.

Ravindra Bagale's Tip

If you try to run both Nginx and Apache on port 80 on the same server, the second one won't start – "Address already in use". Many students waste hours here. Only one can use port 80 at a time: stop the other one (sudo service httpd stop) or give it a different port.

Practice task

List three differences between Nginx and Apache and one situation where you would choose each.