Apache vs Nginx
Apache and Nginx are both production-grade web servers used by millions of sites. The choice between them is not religious — it is technical. Apache's strength is flexibility and compatibility, especially with PHP applications using mod_php and .htaccess configuration. Nginx's strength is performance under high concurrency and as a reverse proxy/load balancer. Many production architectures use both: Nginx as the public-facing load balancer/proxy and Apache handling application logic behind it.
Architecture differences
Apache (prefork MPM): Nginx:
1 connection = 1 process 1 worker handles N connections
process spawned per request event-driven, non-blocking I/O
~8MB RAM per process ~500KB per worker
1000 connections = ~8GB RAM 1000 connections = ~10MB RAM total
This is why Nginx excels at This is why Apache struggles with
high-concurrency workloads the "10,000 connection problem"Performance comparison
| Workload | Apache | Nginx |
|---|---|---|
| Serving static files | Good | Excellent (30-50% faster at high concurrency) |
| Reverse proxy | Good | Excellent (lower memory, more throughput) |
| PHP-FPM applications | Good | Good (similar performance) |
| mod_php applications | Good | Not supported |
| Memory at 1000 connections | ~2-8 GB | ~50-100 MB |
Feature comparison
| Feature | Apache | Nginx |
|---|---|---|
| .htaccess per-directory config | Yes (key differentiator) | No (config only in main files) |
| mod_php (embedded PHP) | Yes | No |
| Dynamic modules | Yes | Yes |
| WebSocket proxying | Yes (mod_proxy_wstunnel) | Yes (native support) |
| Shared hosting | Better (.htaccess) | Worse (needs root to add sites) |
| Config reload | Graceful (apache2ctl graceful) | Graceful (nginx -s reload) |
When to use each
# Choose Apache when:
# - Deploying legacy PHP apps that rely on mod_php or .htaccess
# - Shared hosting environment where tenants need per-directory config
# - CMS platforms (WordPress, Drupal) with rewrite rules in .htaccess
# - Team is more familiar with Apache configuration
# Choose Nginx when:
# - High-traffic site where memory efficiency matters
# - Reverse proxy / load balancer role
# - Serving large amounts of static files (media, downloads)
# - New applications using PHP-FPM, Node.js, Python (WSGI/ASGI), Go
Using both together
Common hybrid architecture:
Internet
↓
Nginx (port 80/443) — public-facing
SSL termination, static file serving, rate limiting, caching
↓
Apache (port 8080, internal only)
PHP application processing (mod_php or PHP-FPM)
.htaccess rules for complex rewrites
Benefits:
- Nginx handles static files and SSL without touching Apache
- Apache handles PHP without needing to deal with SSL or concurrency
- Can add Nginx rate limiting without changing Apache configConclusion
For new deployments in 2025: Nginx is the default choice unless you have a specific reason to use Apache. The main Apache-specific reasons are mod_php requirements or .htaccess-based per-directory configuration for shared hosting. For PHP applications with PHP-FPM, both servers perform similarly. For everything else (reverse proxy, static files, load balancing, API gateway), Nginx has a clear advantage in memory efficiency and configuration simplicity.
FAQ
Why should administrators understand Apache vs Nginx?+
Because this topic affects planning decisions, server lifecycle, compatibility, support expectations, or how you reason about Ubuntu systems before making operational changes.
Do I need a lab for this topic?+
A lab is useful for checking commands and seeing the concept on a real Ubuntu machine, but the main value is understanding the decision, tradeoff, or system behavior clearly.
How should I use this knowledge in production?+
Use it to make better choices, document why those choices were made, and avoid rushed changes that ignore support windows, compatibility, stability, or operational risk.
Need help with Ubuntu administration?
Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.
Hire Me for Support