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

Chapter 6: Web Servers — Nginx and Apache

6.2 Nginx vs Apache

Students in my class always ask: "Sir, which one is better?" Honest answer – both are excellent; the right choice depends on your use case. Think of it this way: Nginx for Mauli Dairy's static order page, and Apache for a WordPress site that needs .htaccess. Look at the comparison below:

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

When you work on a new distribution, always keep the quick-reference table below open. Most beginner mistakes come from using an Ubuntu path on Amazon Linux (or the other way round) – apache2 vs httpd, /var/www/html vs /usr/share/nginx/html. First check the OS with cat /etc/os-release, then pick the path.

Lab

Chala, Mauli Dairy sathi kagdavar nivad kara: static order page aani ek WordPress blog. Pratyekasathi Nginx ki Apache te liha aani varchya table madhli don karane dya. Mag tumchya EC2 var sudo ss -tlnp | grep :80 chalva aani port 80 var aadhich koni aahe ka te bagha.

Quick revision cards

Revise this lesson in two minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens its lesson.

Comparison card: Apache (httpd) vs Nginx. Apache (httpd): A classic web server with .htaccess files and modules. Nginx: A fast web server and reverse proxy.
Comparison: Apache (httpd) vs Nginx · Download PNG

More cards: Ravi Sir's Cards.