Nginx and Apache together serve a large share of the world’s websites. Both are mature, fast and secure. The differences are in architecture and configuration style — which affects memory use under load, how you configure sites, and how well they fit specific applications.

Architecture

Apache uses Multi-Processing Modules (MPMs):

  • prefork — one process per connection; required by the old mod_php; memory-hungry.
  • worker / event — threads handle connections; event hands idle keep-alive connections to a listener thread, making it far more efficient. event + PHP-FPM is the modern setup.

Nginx uses an event-driven, asynchronous model: a few worker processes (usually one per CPU core) each handle thousands of connections in a loop. Memory use stays low and predictable even with many slow or idle clients.

Comparison

Nginx Apache
Connection handling Event-driven Process/thread per connection (event MPM improves this)
Static files Very fast Fast
Memory under many connections Low, predictable Higher, grows with connections
Dynamic content (PHP) Always via PHP-FPM (FastCGI) PHP-FPM or embedded mod_php
Per-directory config No (.htaccess not supported) Yes (.htaccess)
Config style Central, nested blocks Directives, virtual hosts, .htaccess
Reverse proxy / load balancing Excellent, very common Capable (mod_proxy)
Modules Compiled in or dynamic modules Huge set, load/unload easily
Default on Many modern stacks, containers Many shared hosts, RHEL httpd

Performance

For static files and reverse proxying, Nginx is typically lighter and handles high concurrency with less memory. For PHP, both pass work to PHP-FPM in modern setups, and PHP becomes the bottleneck — the web server matters much less than caching, PHP workers and the database. A well-configured Apache event + PHP-FPM is perfectly fast for most sites.

Where Apache with prefork + mod_php struggles is many concurrent connections on limited RAM: each connection ties up a whole PHP-enabled process.

.htaccess: Apache’s biggest advantage (and cost)

.htaccess files let applications and users change server behaviour per directory — rewrites, redirects, access rules — without touching the main config or reloading. That’s why shared hosting and many PHP apps (WordPress plugins, older frameworks) rely on it.

The cost: with AllowOverride All, Apache checks for .htaccess in every directory of every request path. On a VPS you control, you can put the same rules in the main config and disable .htaccess lookups for speed.

Nginx has no equivalent. Rules must go into the server config — meaning you translate .htaccess rules when migrating (most are simple: WordPress needs only try_files). See WordPress permalinks on Nginx.

Configuration style

Nginx:

server {
    server_name example.com;
    root /var/www/example.com;
    location / { try_files $uri $uri/ /index.php?$args; }
    location ~ \.php$ { fastcgi_pass unix:/run/php/php8.3-fpm.sock; include snippets/fastcgi-php.conf; }
}

Apache:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/example.com
    <Directory /var/www/example.com>
        AllowOverride All
        Require all granted
    </Directory>
    <FilesMatch \.php$>
        SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost"
    </FilesMatch>
</VirtualHost>

Many people find Nginx’s config more concise; Apache’s is more familiar to those coming from shared hosting.

Running both: Nginx in front of Apache

A classic combination: Nginx on ports 80/443 terminates TLS, serves static files and caches; Apache behind it (on 127.0.0.1:8080) runs applications that depend on .htaccess. You get Nginx’s efficiency with Apache’s compatibility. Control panels like cPanel and Plesk offer this setup. Pass real client IPs to Apache with mod_remoteip.

Which should you choose?

Situation Choose
New server, modern apps (Node, Python, Go, Docker) as reverse proxy Nginx (or Caddy)
WordPress/PHP on your own VPS Either; Nginx + PHP-FPM is the popular lean stack
Apps that rely heavily on .htaccess Apache (or Nginx in front of Apache)
Migrating from shared hosting with many .htaccess rules Apache is the easiest path
Minimal RAM, high concurrency Nginx
Team already knows one well That one

Also worth a look: Caddy (automatic HTTPS, simple config) and OpenLiteSpeed (Apache-compatible rewrites, built-in caching for WordPress).

Install guides: Nginx on Ubuntu · Apache on Ubuntu.

  • Nginx
  • Apache
  • Web Server