How to config Both Cache in Nginx

Hello,

I am trying to config FastCGI Cache and Proxy Cache in Nginx
I have installed Nginx + Apache2 + PHP-FPM

How I can add both?

Example:

location / {
proxy_pass https://%ip%:%web_ssl_port%;
proxy_cache %domain%;
proxy_cache_valid 200 5m;
proxy_cache_valid 301 302 10m;
proxy_cache_valid 404 10m;
proxy_cache_bypass $no_cache $cookie_session $http_x_update;
proxy_no_cache $no_cache;

set $no_cache 0;

if ($http_cookie ~ PHPSESSID) {
    set $no_cache 1;
}

# FastCGI Cache for PHP
location ~ [^/]\.php(/|$) {
    try_files $uri =404;

    include /etc/nginx/fastcgi_params;
    fastcgi_index index.php;
    fastcgi_param HTTP_EARLY_DATA $rfc_early_data if_not_empty;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    fastcgi_pass %backend_lsnr%;

    # FastCGI Cache rules
    fastcgi_cache %domain%;
    fastcgi_cache_valid 200 6h;
    fastcgi_cache_valid 301 302 6h;
    fastcgi_cache_valid 404 6h;
    fastcgi_cache_bypass $no_cache;
    fastcgi_no_cache $no_cache;

    set $no_cache 0;

    if ($http_cookie ~ PHPSESSID) {
        set $no_cache 1;
    }
}

# Proxy Cache for Static Files
location ~* ^.+\.(%proxy_extensions%)$ {
    try_files $uri @fallback;

    root %sdocroot%;
    access_log /var/log/%web_system%/domains/%domain%.log combined;
    access_log /var/log/%web_system%/domains/%domain%.bytes bytes;

    expires 30d;

    proxy_cache %domain%;
    proxy_cache_valid 200 6h;
    proxy_cache_valid 301 302 6h;
    proxy_cache_valid 404 6h;
    proxy_cache_bypass $no_cache;
    proxy_no_cache $no_cache;

    set $no_cache 0;

    # Disable setting cookies for static files
    fastcgi_hide_header "Set-Cookie";
    add_header X-Proxy-Cache $upstream_cache_status;
}

}

Static files are allready served directly via Nginx so there 0 speed benefits for it …

1 Like

as I don’t see option in hestia for FastCGi cache
How I can Add FastCGi cache manually ??

FastCGI is only availble in Nginx only setups

1 Like

It won’t worth in your case brother.

I am just trying to reduce load on DB

then use redis