Ravindra BagaleCourses & study guides

Chapter 6: Web Servers — Nginx and Apache

6.2 Nginx vs Apache

In my sessions, students often ask: "Sir, which one is better?" Honest answer — both are excellent; the right choice depends on the use case. Bagha the comparison:

Apache HTTP Server is the classic, highly flexible web server with a module for almost everything. Nginx (pronounced "engine-x") was designed to solve the C10K problem (10,000 simultaneous connections) using an event-driven architecture. Today both are widely used, often together.

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.

Ravindra Bagale's Tip

Keep this quick-reference table open whenever you work on a new distribution. Most beginner errors are simply using the Ubuntu path on Amazon Linux (or vice versa) — apache2 vs httpd, /var/www/html vs /usr/share/nginx/html. Check the OS first with cat /etc/os-release, then choose the path.