A
A
Andrey2019-11-18 01:57:54
Nginx
Andrey, 2019-11-18 01:57:54

Is it possible to set different Nginx cache times for different pages?

Dealing with caching in NGINX through fastchi_cache, the following question arose - is it possible to set different cache lifetimes for different pages? That is, for a static page like About Us, set a long time, and for the main page, set a few minutes. I use this design from the manuals:

location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.2-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;
    fastcgi_cache FASTCGICACHE;
    fastcgi_cache_valid 60s;
    add_header X-FastCGI-Cache $upstream_cache_status;
   }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Shatokhin, 2019-11-18
Shults @noroots

Yes. You can add the X-Accel-Expires header on the backend and cache time in it. fastcgi_cache_valid is ignored. dock

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question