Promotions VPS ! Découvrez nos offres du moment avec des prix réduits.
Voir les promos
← Retour aux articles
Article

Optimizing Nginx/Apache2 for Performance on a Linux VPS

Tuning Nginx or Apache2 on a Linux VPS can drastically improve site speed and reduce CPU/RAM usage. Learn how to configure them efficiently.

Mis à jour le 23/10/2025 ~ 2 min de lecture

Optimizing Nginx/Apache2 for Performance on a Linux VPS

Both Nginx and Apache2 can deliver amazing performance on a Linux VPS — if configured properly. Default settings are safe but far from optimal. Let’s fine-tune your web server for maximum speed and stability.

1. Choose between Nginx and Apache2

Nginx is lightweight and efficient for high concurrency. Apache2 is flexible and integrates well with .htaccess. Nginx is generally faster for static sites, while Apache can handle complex PHP setups better with proper tuning.

2. Enable HTTP/2 and Brotli compression

HTTP/2 reduces latency and speeds up page loading. Enable it in your configuration:

listen 443 ssl http2;

Use Brotli compression for better performance:

brotli on;
brotli_comp_level 6;
brotli_types text/html text/css text/javascript application/javascript;

For Apache2, enable:

a2enmod http2
a2enmod brotli
a2enmod deflate

3. Tune PHP-FPM

Edit /etc/php/8.2/fpm/pool.d/www.conf and set reasonable process limits:

pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 5

Adjust values according to your VPS RAM — each PHP process usually consumes 40–60 MB.

4. Cache smartly

On Nginx, use FastCGI caching:

fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=WORDPRESS:10m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";

On Apache2, enable mod_cache and mod_expires for static files caching.

5. Offload traffic via CDN

Use Cloudflare to cache assets globally and reduce load on your VPS. It also adds SSL and DDoS protection automatically.

6. Keep-Alive and buffers

Optimize timeouts and buffer sizes:

keepalive_timeout 65;
sendfile on;
client_max_body_size 20M;
client_body_buffer_size 128k;

7. Monitor performance

Install htop and ngxtop for live metrics. Use GoAccess for log analytics to track response times and visitor activity.

8. Security and process optimization

For Nginx, set worker_processes auto;. In Apache2, disable MPM Prefork and enable MPM Event:

a2dismod mpm_prefork
a2enmod mpm_event

Conclusion

Properly optimized Nginx/Apache2 on your VPS can double your site performance while reducing CPU load. Speed, stability, and scalability all improve. Get your own optimized VPS at https://vps1dollar.com.

Also read: How to Choose a VPS

Blog & ressources