Hostxpeed
Login Get Started →
Control Panel

How to Enable Nginx Caching in HestiaCP

6 min read
27 views
Jun 10, 2026

Prerequisites

Before enabling Nginx caching, make sure you have:

  • SSH access to your VPS
  • Nginx web server

Enable via HestiaCP Web Template

Step 1: Log in to HestiaCP

https://YOUR_SERVER_IP:8083

Step 2: Navigate to WEB Section

Click on WEB in the top menu bar.

Step 3: Set Proxy Template

Edit your domain → Advanced Options:

Set Proxy Template to caching or caching-php.

Manual Nginx Caching Configuration

Edit domain Nginx config:

nano /home/admin/conf/web/nginx.example.com.conf

Add caching directives inside server block:

# Cache static files
location ~* .(jpg|jpeg|png|gif|ico|css|js|pdf|txt|woff|woff2|ttf|svg)$ {
    expires 30d;
    add_header Cache-Control "public, immutable";
}

# Cache HTML pages (for dynamic content)
proxy_cache_path /tmp/nginx_cache levels=1:2 keys_zone=my_cache:10m max_size=1g inactive=60m use_temp_path=off;

location / {
    proxy_cache my_cache;
    proxy_cache_valid 200 60m;
    proxy_cache_valid 404 1m;
    proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
    add_header X-Cache-Status $upstream_cache_status;
}

Enable FastCGI Cache for PHP (Advanced)

mkdir -p /var/cache/nginx
chown www-data:www-data /var/cache/nginx

Add to Nginx main config:

fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=phpcache:100m max_size=1g inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

In domain config:

location ~ .php$ {
    fastcgi_cache phpcache;
    fastcgi_cache_valid 200 60m;
    add_header X-FastCGI-Cache $upstream_cache_status;
}

Test Nginx Configuration

nginx -t

Restart Nginx:

systemctl restart nginx

Verify Caching is Working

Check response headers:

curl -I https://example.com/style.css | grep -i cache

You should see caching headers (Cache-Control, Expires).

✅ Nginx caching has been enabled!

Was this article helpful?