Optimizing Apache and Nginx Servers: A Performance Checklist

Optimizing Apache and Nginx Servers: A Performance Checklist

Let’s be honest—most websites don’t fail because of bad design or poor code. They fail because the server collapses under pressure like a soggy cardboard box. I’ve seen it happen. Heck, I’ve caused it (back in my early days). If you’ve ever stared at a spinning loading wheel thinking, “Why is this happening?!”—this one’s for you.

After 9+ years wrangling Apache and Nginx on everything from shared hosting to high-traffic cloud infrastructure, I’ve built a rock-solid performance checklist. In this post, I’ll walk you through exactly how I tune and optimize both servers so your site stays fast, efficient, and most importantly—up.

No fluff. Just what works.

What You’ll Learn (The Quick Version)

  • How I fine-tune Apache’s modules and worker settings
  • The Nginx settings that actually matter (and which ones are hype)
  • My battle-tested caching and compression setup
  • Monitoring tools I never go without
  • Classic mistakes I’ve made—so you can skip them
  • A final printable checklist for easy reference

Apache vs Nginx – A Speed Duel With a Plot Twist

First, let’s clear this up: Apache isn’t dead. It’s old, yes. But it’s flexible and battle-tested. Nginx, on the other hand, is younger, faster, and built with concurrency in mind. If Apache is a Swiss Army knife, Nginx is a scalpel—it slices through static file requests with surgical precision.

I often use both. Apache for dynamic PHP apps and legacy modules, Nginx for speed and static content. With a reverse proxy setup, you can use Nginx as a buffer to keep Apache from collapsing under load.

If you’re curious about combining the two effectively, I go deeper into that here.

Benchmark First or Fly Blind

Before tweaking a single config file, you need a baseline. Otherwise, how will you know what actually made a difference?

Here are my go-to tools:

ApacheBench (ab): Brutal and beautiful. Great for quick stress tests.

htop: For seeing what’s choking the CPU or memory.

GTmetrix / Pingdom: Because even if your server is fine, the browser might tell a different story.

GTmetrix


Tip: Always benchmark at different times of day to account for real-world traffic patterns.

Apache Optimization (How I Keep It From Eating RAM for Breakfast)

Use mpm_event, Not prefork

Apache’s default prefork module is like opening a new tab every time you visit a website—resource-heavy and slow. I switch to mpm_event and keep my settings lean:

apache

CopyEdit

<IfModule mpm_event_module>

    StartServers             2

    MinSpareThreads         25

    MaxSpareThreads         75

    ThreadsPerChild         25

    MaxRequestWorkers      150

    MaxConnectionsPerChild 500

</IfModule>

Want more Apache tuning tricks? Check out my detailed guide here.

 Disable .htaccess (Where You Can)

 Disable .htaccess

I get it—.htaccess is convenient. But every time a request comes in, Apache checks all the parent directories for .htaccess files. That adds up. Unless you’re on shared hosting, move those rules into your main config and set:

apache

CopyEdit

AllowOverride None

Less file access, more speed.

 Enable Compression and Caching

Compression saves bandwidth. Caching saves sanity. Combine both with these modules:

  • mod_deflate – Compresses your content.
  • mod_expires – Controls browser caching.

Here’s a basic snippet:

apache

CopyEdit

<IfModule mod_deflate.c>

    AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript

</IfModule>

<IfModule mod_expires.c>

    ExpiresActive On

    ExpiresByType image/jpg “access plus 1 year”

    ExpiresByType text/css “access plus 1 month”

</IfModule>

 Ditch Unused Modules

Apache ships with modules most of us never use. Audit your active ones and turn off anything not essential.

Use:

bash

CopyEdit

apache2ctl -M

Then disable with a2dismod module-name.

Nginx Optimization (Lean, Mean, and Surprisingly Friendly)

 Worker Settings That Don’t Suck

Out of the box, Nginx uses only one worker. That’s cute, but you’ve got more cores than that, right?

In nginx.conf:

nginx

CopyEdit

worker_processes auto;

worker_connections 1024;

That alone can double your throughput.

 Keep Connections Alive

Reusing TCP connections speeds up browsing—especially over HTTPS. Nginx makes this easy:

nginx

CopyEdit

keepalive_timeout 65;

keepalive_requests 100;

Bonus tip: If you’re using Nginx as a reverse proxy, enable keepalive upstream too.

 Serve Static Files Directly

Nginx shines at serving images, CSS, and JS. Let it do the work:

CSS

nginx

CopyEdit

location /assets/ {

    root /var/www/html;

    expires 30d;

    add_header Cache-Control “public”;

}

Fast and cacheable.

FastCGI Cache (Dynamic Sites Need Love Too)

If you’re running PHP apps, cache that output:

nginx

CopyEdit

fastcgi_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYCACHE:10m inactive=60m;

fastcgi_cache MYCACHE;

fastcgi_cache_valid 200 1h;

This alone reduced load times on one of my client sites by 40%.

Tricks That Work on Both Servers

 Reverse Proxy Magic

Use Nginx in front of Apache for the best of both worlds. You can configure Nginx to proxy dynamic requests to Apache while handling static content itself.

I cover how this works in detail in this post.

 Monitor Everything (Yes, Everything)

Here’s what I keep an eye on:

  • CPU, memory, and I/O (via htop or Netdata)
  • Request per second
  • 5xx errors (they sneak in)

I also recommend these tools if you want your monitoring setup to be effective without becoming a full-time job.

 Secure While You Optimize

Tuning your server means nothing if it’s vulnerable. Stick with strong SSL configs, disable unused ports, and monitor login attempts.

Not sure what to secure? Start with my server security guide.

What I Got Wrong (Learn from My Pain)

These are all… let’s call them “learning moments”:

  • I once left mpm_prefork active with mod_php and watched my RAM vanish in 10 minutes.
  • I applied someone else’s tuning script without understanding it. Oops.
  • I forgot to benchmark before and after changes. Meaning I had no idea what helped.

Save yourself the headache: test configs on a staging server. Always.

Final Performance Checklist

Here’s the quick version you can copy and tape to your wall:

 Use mpm_event for Apache
  Disable .htaccess (use main config)
  Enable Gzip or Deflate compression
Set cache headers
  Set worker_processes auto; in Nginx
  Use FastCGI or proxy caching
  Turn off unused modules
  Monitor with Netdata or htop
  Benchmark before and after every change
  Keep logs clean and rotated

Wrapping Up (And a Bit of Tough Love)

Most slow websites aren’t broken—they’re just poorly tuned. Apache and Nginx are both powerful tools, but like all tools, they need attention. The good news? Once you get it right, you usually don’t have to touch it again for a while.

If you want more real-world techniques, check out my guide on server optimization techniques or how to reduce server downtime.