A
A
Alexander2017-11-22 20:02:22
PHP
Alexander, 2017-11-22 20:02:22

Why is the cached page not returned, in the headers always X-Fastcgi-Cache:MISS?

Setting up VPSku on debian 9
Configuration
MariaDB, Nginx, Php-Fpm
script - Joomla
want to set up nginxa caching

sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        keepalive_requests 100000;

        fastcgi_cache_path /var/www/html/nginx-cache levels=1:2 keys_zone=fastcgicache:100m inactive=600m max_size=640m;
        fastcgi_cache_key "$scheme$request_method$host$request_uri";

location ~ [^/]\.php(/|$) {
        proxy_ignore_headers Expires Cache-Control;
        fastcgi_cache fastcgicache; # The name of the cache key-zone to use
        fastcgi_cache_valid 200 360m;
        fastcgi_cache_methods GET HEAD;
        add_header X-Fastcgi-Cache $upstream_cache_status; # Add header so we can see if the cache hits or misses
        fastcgi_split_path_info  ^(.+\.php)(/.+)$;
        fastcgi_index            index.php;
        fastcgi_pass             unix:/var/run/php/php7.0-fpm.sock; # for Ubuntu 17.04
    include                  fastcgi_params;
    fastcgi_param   PATH_INFO       $fastcgi_path_info;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

But the server always responds
HTTP/1.1 200 OK
Server: nginx/1.10.3
Date: Wed, 22 Nov 2017 16:01:29 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Vary: Accept-Encoding
Expires: Wed, 17 Aug 2005 00:00:00 GMT
Last-Modified: Wed, 22 Nov 2017 16:01:29 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
X-Fastcgi-Cache: MISS
Content-Encoding: gzip

X-Fastcgi-Cache: MISS - the page is not cached and accordingly Waiting (TTFB) 600-800ms
I configured something incorrectly, cache files are not created

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bahadir Ishmatov, 2020-06-22
@bahinnn

although more than one year has passed, I’ll answer for others - caching is configured correctly, it’s just not enough:

location ~ [^/]\.php(/|$) {
...
fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
...
}

this:
post-check=0, pre-check=0
and this is
Pragma: no-cache
better removed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question