web server performance

Apache vs Nginx on VPS: Which One to Choose?

June 2026 · 5 min read

Apache and Nginx are the two web servers that have dominated the market for years, but they work very differently at the architectural level. Understanding these differences helps you choose the right one for your workload.


Apache: Process-based Architecture

Apache uses a process-based or thread-based model where each connection gets its own process or thread. This makes it easy to configure on a per-directory basis using .htaccess files.

Pros

Cons

Nginx: Event-driven Architecture

Nginx uses an event-driven, asynchronous architecture. A single server can handle multiple connections simultaneously without spawning a new process for each connection.

Pros

Cons


Comparison Table

CriteriaApacheNginx
ArchitectureProcess/Thread-basedEvent-driven
RAM UsageHigherLower
Static filesGoodMuch faster
.htaccessSupportedNot supported
Reverse proxyCan do itBetter suited
PHP supportmod_php built-inVia PHP-FPM

Which One Should You Choose?

Choose Apache if

Choose Nginx if


Summary

Nginx is a better choice in terms of performance for low-RAM VPS, but Apache still has advantages for applications that heavily rely on .htaccess. Some organizations use both: Nginx as the front-end receiving requests and forwarding them to Apache — getting the best of both worlds.

Using Both: Nginx + Apache

Some organizations use Nginx as a front-end reverse proxy receiving traffic from the internet and forwarding it to Apache running on port 8080. This way they get the benefits of both — Nginx handles static files and SSL termination, while Apache supports .htaccess and legacy applications.

# Nginx listens on port 80/443, forwards to Apache on port 8080
server {
    listen 80;
    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
    # Static files served directly from Nginx
    location ~* \.(css|js|jpg|png|gif|ico|woff2)$ {
        root /var/www/html;
        expires 1y;
    }
}

Verify Nginx is Working Correctly

After setting up or making changes to Nginx, verify that everything is running as expected:

# Check Nginx syntax
nginx -t

# Check if Nginx is running
systemctl status nginx

# Test a request to your site
curl -I https://yourdomain.com

# Check active connections
netstat -an | grep :80 | grep ESTABLISHED | wc -l
Tip: Use nginx -t before reloading to catch syntax errors early and prevent downtime.

Common Issues & Troubleshooting

Nginx: "502 Bad Gateway" after changing PHP-FPM socket

The socket name in your config doesn't match the actual PHP-FPM socket:

# Check where PHP-FPM socket is located
ls /run/php/
# You might see php8.3-fpm.sock or php8.1-fpm.sock

# Fix it in your Nginx site config
fastcgi_pass unix:/run/php/php8.3-fpm.sock;

nginx -t && systemctl reload nginx

Apache: .htaccess doesn't work / mod_rewrite doesn't redirect

You need to enable AllowOverride All in your VirtualHost config:

<Directory /var/www/html>
    AllowOverride All
    Require all granted
</Directory>

# Enable mod_rewrite
a2enmod rewrite
systemctl restart apache2

Nginx: Config changes don't take effect

# Test config before reloading
nginx -t
# If it passes, reload
systemctl reload nginx

Apache: Memory usage is abnormally high

Apache is using the prefork MPM which spawns many processes. Try switching to the event MPM:

a2dismod mpm_prefork
a2enmod mpm_event php8.3-fpm
systemctl restart apache2

Frequently Asked Questions

Can I switch from Apache to Nginx mid-deployment?

Yes, but you'll need to convert all your config — Apache VirtualHosts become Nginx server blocks, and .htaccess rewrite rules become Nginx location directives. It's recommended to test on a staging environment first.

For a 1 GB RAM VPS, which should I choose?

Nginx is clearly the winner — it uses significantly less RAM than Apache. For WordPress on low-RAM VPS, Nginx + PHP-FPM saves about 200–400 MB compared to Apache + mod_php.

Can Nginx handle multiple domains (virtual hosting)?

Yes, create multiple server blocks in /etc/nginx/sites-available/ and symlink them to sites-enabled/, similar to Apache VirtualHosts.

I need .htaccess but want Nginx performance. Is that possible?

Not directly — Nginx doesn't support .htaccess. If your application depends heavily on .htaccess, you'll either need to use Apache or the Nginx+Apache stack. Alternatively, you can migrate your .htaccess rules directly into your Nginx config.