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

WorkloadApacheNginx
Serving static filesGoodExcellent (30-50% faster at high concurrency)
Reverse proxyGoodExcellent (lower memory, more throughput)
PHP-FPM applicationsGoodGood (similar performance)
mod_php applicationsGoodNot supported
Memory at 1000 connections~2-8 GB~50-100 MB

Feature comparison

FeatureApacheNginx
.htaccess per-directory configYes (key differentiator)No (config only in main files)
mod_php (embedded PHP)YesNo
Dynamic modulesYesYes
WebSocket proxyingYes (mod_proxy_wstunnel)Yes (native support)
Shared hostingBetter (.htaccess)Worse (needs root to add sites)
Config reloadGraceful (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 config

Conclusion

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.

Need help with Ubuntu administration?

Work directly with Muhammad Irfan Aslam for Ubuntu Server, Linux, cloud, Docker, DevOps, CI/CD, or infrastructure troubleshooting support.

Work with Muhammad Irfan Aslam