Nginx vs Apache: Which Web Server Is Best for Your VPS in 2026
Nginx vs Apache compared for VPS users. Performance benchmarks, memory usage, configuration differences, and which web server to choose for your Linux VPS in 2026.
Daniel Meier
Systems Administrator
You have a Linux VPS. You need to serve websites. The first real decision you face is which web server to install. In 2026, that choice almost always comes down to two options: Nginx and Apache. Both are free, both are battle-tested, and both power millions of websites. But they work very differently under the hood, and picking the wrong one for your use case can cost you performance, memory, and hours of troubleshooting.
This guide breaks down exactly how Nginx and Apache differ, where each one excels, and which one you should install on your VPS based on what you are actually building.
If you want the quick version before we get into the details: use Nginx if you are serving static content, running a reverse proxy, or working with limited VPS resources. Use Apache if you need .htaccess support, are running shared hosting with multiple users, or your application specifically requires Apache modules. For most VPS users in 2026, Nginx is the better default choice.
Now let us explain why.
Apache was released in 1995 and has been the most popular web server on the internet for most of its history. It uses a process-based or thread-based model to handle incoming connections. When a request comes in, Apache assigns a worker process or thread to handle it. That worker stays dedicated to that connection until the response is complete.
Apache offers three main processing modules, called MPMs:
- prefork MPM — spawns a new process for each connection. The most compatible but uses the most memory. Required for mod_php.
- worker MPM — uses threads instead of processes. More memory efficient but some modules are not thread-safe.
- event MPM — the newest option. Handles keep-alive connections more efficiently by freeing up threads when a connection is idle. This is the default in modern Apache installations.
The key thing to understand is that Apache creates a new process or thread for every active connection. If you have 500 simultaneous visitors, Apache needs 500 workers. Each worker consumes memory. On a VPS with 2 GB of RAM, this can become a problem fast.
Nginx was created in 2004 specifically to solve the performance problems that Apache had with high traffic. It uses an event-driven, asynchronous architecture. Instead of creating a new process for each connection, Nginx uses a small number of worker processes that each handle thousands of connections simultaneously using an event loop.
Think of it this way. Apache is like a restaurant where every customer gets their own waiter who stands at the table the entire meal. Nginx is like a restaurant with a few very efficient waiters who take orders from multiple tables, put them in, and serve food as it comes out of the kitchen. The Nginx approach handles more customers with fewer staff.
This architectural difference is why Nginx uses dramatically less memory under load. A VPS serving 10,000 concurrent connections with Nginx might use 200 MB of RAM. Apache serving the same traffic could easily consume 2 GB or more depending on the MPM configuration.
For serving static files like HTML, CSS, JavaScript, and images, Nginx is significantly faster than Apache. This is not even close. Nginx was designed from the ground up to serve static content efficiently. In benchmarks, Nginx consistently serves 2 to 3 times more requests per second than Apache for static files while using a fraction of the memory.
If your website is mostly static content, a portfolio site, a documentation site, a landing page, Nginx is the obvious choice.
For dynamic content like PHP applications (WordPress, Laravel, Drupal), the performance gap narrows considerably. Both Apache and Nginx need to pass dynamic requests to a backend processor like PHP-FPM. The actual processing time is determined by PHP, not the web server.
Apache can process PHP directly through mod_php, which embeds the PHP interpreter into every Apache worker process. This is simple to set up but wastes memory because every worker loads PHP even when serving static files. Nginx always uses PHP-FPM as a separate process, which is more memory efficient because the web server and PHP workers scale independently.
For WordPress specifically, both servers perform similarly when properly configured. The bottleneck is almost always PHP and the database, not the web server itself.
This is where Nginx pulls far ahead. Under heavy load with thousands of simultaneous connections, Nginx maintains consistent performance while Apache starts to struggle. Apache's memory usage grows linearly with connections. Nginx's stays nearly flat.
If you expect traffic spikes or run a site that maintains many open connections (websockets, long polling, streaming), Nginx handles it much better on limited VPS resources.
Apache uses a distributed configuration model. The main config lives in /etc/apache2/apache2.conf (Debian/Ubuntu) or /etc/httpd/conf/httpd.conf (CentOS/RHEL), but individual sites and directories can override settings using .htaccess files placed in any directory.
# /etc/apache2/sites-available/mysite.conf
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/mysite
<Directory /var/www/mysite>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>The .htaccess feature is both Apache's biggest advantage and its biggest performance weakness. It lets users modify server behavior without touching the main config, which is essential for shared hosting. But Apache has to check for .htaccess files in every directory on every request, which adds overhead.
Nginx uses a centralized configuration model. All settings live in /etc/nginx/nginx.conf and site-specific configs in /etc/nginx/sites-available/. There is no equivalent to .htaccess. Every configuration change requires editing the config files and reloading Nginx.
# /etc/nginx/sites-available/mysite.conf
server {
listen 80;
server_name example.com;
root /var/www/mysite;
index index.html index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|woff2)$ {
expires 30d;
add_header Cache-Control "public, immutable";
}
}Nginx configuration syntax is cleaner and more intuitive once you learn it. The location block system is powerful and lets you handle different URL patterns with different rules. But the learning curve is steeper than Apache for beginners, and the lack of .htaccess means you need SSH access to make any configuration changes.
Apache has a dynamic module system. You can load and unload modules at runtime without recompiling. Need URL rewriting? Enable mod_rewrite. Need SSL? Enable mod_ssl. Need PHP? Load mod_php. The module ecosystem is massive and covers almost every use case imaginable.
# Enable a module
a2enmod rewrite
a2enmod ssl
a2enmod headers
# Disable a module
a2dismod autoindex
# Restart to apply
systemctl restart apache2This flexibility is one of the reasons Apache has remained popular for so long. If you need a specific feature, there is probably an Apache module for it.
Nginx modules are compiled into the binary at build time. You cannot load or unload them dynamically in the standard open-source version. The modules that come with your distribution's Nginx package cover most common needs (SSL, gzip, proxy, fastcgi), but if you need something unusual, you may need to compile Nginx from source with the additional module.
Nginx Plus, the commercial version, supports dynamic modules, but for most VPS users the open-source version with its default modules is more than sufficient.
This is one of Nginx's strongest use cases. Nginx was built to be a reverse proxy, and it excels at sitting in front of application servers (Node.js, Python, Ruby, Go) and forwarding requests to them.
# Nginx reverse proxy to a Node.js app
server {
listen 80;
server_name api.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}Apache can also function as a reverse proxy using mod_proxy, but Nginx handles it with less overhead and better performance under load. If you are running any kind of application server behind a web server, Nginx is the standard choice in 2026.
Many production setups actually use both: Nginx as the front-facing reverse proxy and load balancer, with Apache running behind it for applications that specifically need Apache features.
Both servers handle SSL/TLS well and both work with Let's Encrypt for free certificates. The setup process is slightly different but equally straightforward.
# Install certbot
apt install certbot python3-certbot-nginx
# Get certificate
certbot --nginx -d example.com -d www.example.comCertbot automatically modifies your Nginx config to add SSL settings and sets up auto-renewal. The whole process takes about 30 seconds.
# Install certbot
apt install certbot python3-certbot-apache
# Get certificate
certbot --apache -d example.com -d www.example.comSame process, different plugin. Both work reliably. SSL performance is essentially identical between the two servers for typical VPS workloads.
This is where the choice matters most for VPS users. Your server has limited RAM, and every megabyte counts.
A fresh Nginx installation with a basic site configured uses about 5 to 10 MB of RAM. A fresh Apache installation with the event MPM uses about 30 to 50 MB. Under load, the gap widens dramatically. Nginx serving 1,000 concurrent connections might use 50 MB. Apache with prefork MPM serving the same traffic could use 500 MB or more.
On a 1 GB VPS, this difference is the difference between your server running smoothly and your server running out of memory and crashing. On a 4 GB VPS, it means more RAM available for your actual application, database, and caching layers.
If you are running a VPS with limited resources, every optimization matters. Our cheap Linux VPS guide covers how to get the most out of budget VPS plans.
Despite Nginx's performance advantages, there are legitimate reasons to choose Apache:
- You need .htaccess support. Many PHP applications (WordPress plugins, Magento, Joomla) rely on .htaccess for URL rewriting and access control. While you can translate these rules to Nginx config, it is extra work.
- You are running shared hosting. If multiple users need to configure their own sites without SSH access, Apache's .htaccess system is essential.
- Your application requires specific Apache modules. Some legacy applications depend on mod_rewrite rules or other Apache-specific features that do not have direct Nginx equivalents.
- You are already familiar with Apache. If you know Apache inside and out and your site performs fine, switching to Nginx just because it is trendy is not worth the migration effort.
- You need per-directory authentication. Apache's .htpasswd and directory-level access control is simpler to set up than Nginx's equivalent.
For most VPS users in 2026, Nginx is the better choice:
- You are serving mostly static content. Nginx is dramatically faster for static files.
- You are running a reverse proxy. Nginx was built for this and handles it with minimal overhead.
- Your VPS has limited RAM. Nginx uses a fraction of the memory that Apache needs.
- You expect high traffic or traffic spikes. Nginx handles concurrent connections much better.
- You are running a modern application stack. Node.js, Python (Django/Flask), Go, Ruby — all of these run behind Nginx as a reverse proxy.
- You want better out-of-the-box security. Nginx's minimal default configuration has a smaller attack surface than Apache's feature-rich defaults.
Need to brush up on your terminal skills before setting up a web server? Our Linux commands guide covers everything you need to know for VPS administration.
Here is the complete setup for Nginx on a fresh Ubuntu VPS:
# Install Nginx
apt update
apt install nginx -y
# Start and enable
systemctl start nginx
systemctl enable nginx
# Check status
systemctl status nginx
# Open firewall
ufw allow 'Nginx Full'After installation, visit your server's IP address in a browser. You should see the default Nginx welcome page. From there, create your site config in /etc/nginx/sites-available/, symlink it to sites-enabled, and reload Nginx.
# Create site config
nano /etc/nginx/sites-available/mysite.conf
# Enable it
ln -s /etc/nginx/sites-available/mysite.conf /etc/nginx/sites-enabled/
# Test config syntax
nginx -t
# Reload
systemctl reload nginxAlways run nginx -t before reloading. It checks your configuration for syntax errors without affecting the running server. This saves you from accidentally taking your site down with a typo.
And here is the equivalent for Apache:
# Install Apache
apt update
apt install apache2 -y
# Start and enable
systemctl start apache2
systemctl enable apache2
# Check status
systemctl status apache2
# Open firewall
ufw allow 'Apache Full'# Create site config
nano /etc/apache2/sites-available/mysite.conf
# Enable it
a2ensite mysite.conf
# Disable default site
a2dissite 000-default.conf
# Test config
apachectl configtest
# Reload
systemctl reload apache2Apache uses a2ensite and a2dissite commands to manage which site configurations are active. The apachectl configtest command is Apache's equivalent of nginx -t.
You do not have to choose just one. A common production setup uses Nginx as the front-facing server on ports 80 and 443, handling SSL termination, static file serving, and caching. Apache runs on a different port (like 8080) behind Nginx, handling only the dynamic PHP requests that need Apache-specific features.
# Nginx config — proxy PHP requests to Apache
server {
listen 80;
server_name example.com;
# Serve static files directly with Nginx
location ~* \.(css|js|jpg|jpeg|png|gif|ico|svg|woff2)$ {
root /var/www/mysite;
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;
}
}This gives you the best of both worlds: Nginx's speed for static content and connection handling, plus Apache's .htaccess support and module ecosystem for dynamic content. The tradeoff is added complexity in your server configuration.
# /etc/nginx/nginx.conf
worker_processes auto;
worker_connections 1024;
http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
gzip on;
gzip_types text/plain text/css application/json application/javascript text/xml;
}Set worker_processes to auto so Nginx uses one worker per CPU core. worker_connections determines how many simultaneous connections each worker handles. Enable sendfile for efficient static file serving. Enable gzip to compress responses and reduce bandwidth.
# /etc/apache2/mods-available/mpm_event.conf
<IfModule mpm_event_module>
StartServers 2
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 150
MaxConnectionsPerChild 0
</IfModule>The most important setting is MaxRequestWorkers. This controls the maximum number of simultaneous connections Apache will handle. Set it too high and Apache consumes all your RAM. Set it too low and visitors get connection refused errors during traffic spikes. For a 2 GB VPS, 150 is a reasonable starting point with the event MPM.
Hardware matters too. If you want the fastest possible web server performance, check out our Ryzen 9 9950X performance breakdown to see how modern CPU architecture impacts real server workloads.
Both servers are secure when properly configured, but they have different default behaviors.
Nginx has a smaller attack surface by default because it includes fewer modules and features out of the box. Apache's rich feature set means more potential attack vectors if modules are enabled but not properly configured. Disable any Apache modules you are not using.
Both servers should be configured to hide version information, set proper security headers, and restrict access to sensitive directories. Here are the basics for each:
# Nginx security headers
server {
server_tokens off;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
}# Apache security headers
<VirtualHost *:80>
ServerTokens Prod
ServerSignature Off
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-Content-Type-Options "nosniff"
Header always set X-XSS-Protection "1; mode=block"
</VirtualHost>For the majority of VPS users in 2026, Nginx is the better default choice. It uses less memory, handles more concurrent connections, serves static content faster, and works perfectly as a reverse proxy for modern application stacks. The configuration syntax is clean once you learn it, and the ecosystem of tutorials and documentation is excellent.
Choose Apache if you specifically need .htaccess support, are running a shared hosting environment, or have applications that depend on Apache-specific modules. There is nothing wrong with Apache. It powers a huge portion of the internet and it is not going anywhere.
The worst choice is not picking either one. It is not optimizing whichever one you pick. A well-tuned Apache server will outperform a poorly configured Nginx server every time. Whichever you choose, take the time to configure it properly for your VPS resources and your specific workload.
Ready to set up your web server? BlastVPS Linux VPS plans come with full root access, NVMe storage, and your choice of Ubuntu, Debian, CentOS, Rocky Linux, or AlmaLinux. Deploy in under 60 seconds.
If you are deciding between a VPS and a dedicated server for your web hosting needs, our VPS vs dedicated server comparison helps you figure out which makes sense for your traffic level and budget.
Ready to Deploy?
Get a high-performance VPS with instant setup, full root access, and 24/7 support.
Written by Daniel Meier
Systems Administrator
Specializes in Windows & Linux server environments with a focus on security hardening.