0

I'm using webpagetest and pagespeed for optimisation. But both are saying that no cache control has been implemented even though I have it in the config.

config below:

server {
        #listen 80;
        root /var/www/html/public;
    index index.html index.htm index.php;
    server_name thewebsite.com; # managed by Certbot

    location ~* \.(js|css|png|jpg|webp)$ {
        expires 1M;
        add_header Cache-Control "max-age=2629746, public";
    }


    location / {
            try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
    }

    location = /livewire/livewire.js {
        expires off;
        try_files $uri $uri/ /index.php?$query_string;
    }

   location /nginx_status {
      stub_status on;
      access_log   off;
      allow 127.0.0.1;
      deny all;
    }

}

Expires map

map $sent_http_content_type $expires { default off; text/html epoch; text/css max; application/javascript max; ~image/ epoch; }

server {
location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; }

    listen 80 ;
    server_name thewebsite.com;
return 404; # managed by Certbot

expires $expires;

}

magicianiam
  • 101
  • 3

1 Answers1

0

I am doubtful about 1M. please try 30d instead of 1M and change add_header line to this. also Pragma provides cached header to old clients and some online tools may consider them:

expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
Omid Estaji
  • 265
  • 2
  • 3
  • 14