The C10k Problem is Real, and Apache is Losing
If you are still serving static assets directly through Apache 2.2 with mod_php, you are burning money. I watched a client's server melt last week—a standard CentOS 5 box hosting a popular vBulletin forum. Traffic spiked, Apache spawned 150 worker processes, and the machine started swapping to disk. Game over.
The issue isn't the traffic volume; it's the architecture. Apache's prefork model assigns a heavy thread to every connection, even if the user is on a slow 3G mobile dongle just downloading a logo. Your expensive RAM is being held hostage by slow clients.
The solution is not "buy more RAM." The solution is Nginx.
The Architecture: Nginx as the Bouncer
By placing Nginx 0.8.x in front of Apache, we create a buffer. Nginx is event-driven and asynchronous. It can handle thousands of concurrent connections with a tiny memory footprint. It rapidly accepts the request, buffers it, and hands it off to Apache only when ready. Apache does the heavy lifting (PHP/MySQL) and immediately hands the result back to Nginx to trickle down to the client.
This is often called the "LEMP" or hybrid stack. Here is how to configure it correctly on a CoolVDS instance running CentOS 5.5.
1. Installation
Don't use the default outdated repos. Use the EPEL repository or compile from source to get the stable 0.8.x branch.
yum install nginx
2. The Reverse Proxy Configuration
We need to tell Nginx to forward dynamic requests to Apache (running on port 8080) while serving static files directly to save CPU cycles.
server {
listen 80;
server_name example.no;
# Serve static files directly - huge performance boost
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
root /var/www/vhosts/example.no/httpdocs;
access_log off;
expires 30d;
}
# Pass everything else to Apache
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Critical for handling slow clients
proxy_buffering on;
proxy_buffer_size 8k;
proxy_buffers 8 8k;
}
}
Pro Tip: Install mod_rpaf on the Apache side. Without it, Apache will see all traffic coming from 127.0.0.1 (localhost) instead of the real visitor IP. This breaks your analytics and security logs.
Why Hardware and Location Still Matter
Software optimization can only go so far. If your underlying I/O is slow, your database will bottleneck regardless of your Nginx config. This is where infrastructure choices become critical.
At CoolVDS, we have moved away from standard SATA drives for our high-performance tier. We utilize enterprise-grade RAID-10 SAS 15k RPM storage arrays (and are currently testing early SSD technology for database caching). When your MySQL innodb_buffer_pool fills up, you need that disk throughput to prevent locking.
The Norwegian Advantage
For those of you targeting the Nordic market, latency is the silent killer. Hosting in Germany or the US adds 20-50ms to every packet round trip. By utilizing our Oslo datacenter, you connect directly to the NIX (Norwegian Internet Exchange).
Furthermore, with the Personopplysningsloven (Personal Data Act) being strictly enforced by Datatilsynet, keeping your data within Norwegian borders is the safest bet for compliance. Don't risk Safe Harbor complications by hosting sensitive customer data across the Atlantic.
DDoS Mitigation via Nginx
One final benefit of this setup is security. We can use Nginx as a first line of defense against script kiddies trying to flood the server.
http {
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
server {
location /login.php {
limit_req zone=one burst=5;
proxy_pass http://127.0.0.1:8080;
}
}
}
This configuration limits a specific IP to 1 request per second on the login page. It’s simple, effective, and keeps the load off Apache.
Ready to Stabilize?
Stop waking up at 3 AM to restart httpd. Implement a reverse proxy today. If you need a sandbox to test this configuration without risking your production environment, spin up a CoolVDS Xen VPS. We offer root access and unmetered bandwidth on our gigabit uplink.
Deploy your CentOS 5 instance on CoolVDS in under 2 minutes.