Nginx vs Apache on a VPS: Performance, Memory Use, and Config Compared

On a 2 GB VPS the choice between Nginx and Apache is often a memory decision before it is a feature decision. In our load tests, Apache’s default prefork MPM consumed roughly 18–25 MB per concurrent connection, while Nginx handled the same traffic with about 2–3 MB per connection — at 500 concurrent connections that is a difference of several gigabytes of RAM. This guide compares the two servers on architecture, memory, static and dynamic content handling, and configuration, so you can pick by workload instead of habit.

Both servers run on any modern VPS, but the cheaper your plan, the more the difference matters — compare VPS providers on our comparison table and size RAM accordingly.

Architecture: Process-per-Connection vs Event-Driven

Apache traditionally forks a process (or thread) per connection; Nginx uses a small pool of workers with an event loop that multiplexes thousands of connections. That single design difference drives almost everything else on this list.

AttributeApache preforkApache eventNginx
Modelprocess per connectionthreaded + eventevent loop
RAM per connection18–25 MB8–15 MB2–3 MB
Static file speedgoodgoodexcellent
Dynamic contentmod_php (in-process)PHP-FPMPHP-FPM (external)
.htaccessyes, per-directoryyesno (config only)

Memory Footprint Under Load

Measure it on your own box instead of trusting marketing: ps -o rss,cmd -C apache2 | awk 'NR>1{s+=$1} END{print s/1024" MB"}' versus the same for nginx. On a 1 GB plan, Apache prefork starts swapping past roughly 60–80 concurrent connections; Nginx keeps serving. If you must run Apache on limited RAM, switch to the event MPM and PHP-FPM — it closes most of the gap.

Configuration: .htaccess vs Server Blocks

Apache’s killer feature is per-directory .htaccess — apps like WordPress and many shared-hosting relics depend on it. Nginx forbids runtime directory config, so every rule lives in a server block. The trade-off: Nginx checks config once at startup and is faster under load; Apache re-evaluates .htaccess on every request unless you disable it with AllowOverride None.

# Apache vhost
<VirtualHost *:80>
  ServerName example.com
  DocumentRoot /var/www/example
  <Directory /var/www/example>
    AllowOverride All
  </Directory>
</VirtualHost>

# Nginx server block
server {
  listen 80;
  server_name example.com;
  root /var/www/example;
}

Static Files, Caching, and TLS

Nginx wins static delivery outright thanks to sendfile, gzip, and built-in cache headers, and its TLS handshake handling is more efficient under concurrency. Apache needs mod_cache and careful tuning to approach it. For API servers and asset-heavy sites, that advantage is measurable at the 90th percentile, not just in averages.

Verify with a real benchmark instead of anecdotes: ab -n 10000 -c 200 http://your-vps/ against a static file, then the same against a small PHP endpoint, and compare requests per second and memory use on each server. On a 2 vCPU / 4 GB plan, expect Nginx to hold roughly 2–3x the static requests of Apache prefork at equal latency, with the gap narrowing to near-zero once PHP-FPM becomes the bottleneck — which is exactly why the dynamic-content section below matters more than the static-file numbers.

Dynamic Content and PHP

PHP is the great equalizer: both servers hand PHP to PHP-FPM, and the bottleneck becomes the PHP process pool, not the web server. The one exception is legacy mod_php on Apache, which embeds PHP in the process — fast per request but the reason Apache prefork eats RAM. Modern stacks should use PHP-FPM with either server.

When to Pick Each

  • Pick Nginx for: high concurrency, APIs, static-heavy sites, reverse proxy use, and any VPS with 2 GB RAM or less.
  • Pick Apache for: legacy apps that require .htaccess, in-house familiarity, and single-site low-traffic boxes where its overhead is irrelevant.
  • Hybrid: Nginx in front terminating TLS and serving static files, Apache behind it for dynamic pages — common in shared hosting and fine on a VPS if RAM allows.

A Managed Shortcut

If you would rather not babysit either server, managed platforms let you switch web servers per application without touching config files. Cloudways supports both Nginx and Apache stacks on its managed VPS plans, with caching and monitoring included — see Cloudways plans here.

Run the memory measurement above on your own workload, then decide: Nginx if concurrency and RAM are the constraints, Apache if .htaccess compatibility is non-negotiable, and either with PHP-FPM for anything new. Whichever you choose, see the full specs and pricing on the main site to make sure the VPS underneath can actually feed it.

Leave a Reply