-1

I'm using a minimal Ubuntu server 16.04 with Nginx 1.10.3 (to which I moved from Apache 2 days ago). On this environment, I run a minimal Wordpress site (5 plugins, no customization).

location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
    expires 365d;
}

location ~* \.(pdf)$ {
    expires 30d;
}

I pasted that code inside the server block in the default.conf file of Nginx (to use it with other sites if I'd need), and restarted:

systemctl restart nginx.service

Yet when running GPI test I still get “Leverage browser caching” for many jpg files, even though “jpg” is already included in the directive.

All documentation I found, so far, deals exactly with what I already tried. Any ideas? Maybe most doc is outdated? Maybe that’s a bug in the current release of Nginx?

  • "to which I moved from Apache" means he moved from Apache to nginx. – Tero Kilkanen Aug 13 '17 at 21:43
  • What is the complete default.conf? – Tero Kilkanen Aug 13 '17 at 21:45
  • Browser caching uses a bunch of headers, I suspect the expires directive only affects one of them. Can you please do "curl -i contfix.co.il" (or to whatever your main domain is that doesn't forward" and edit your question to include the response headers? – Tim Aug 14 '17 at 1:20
  • When I do curl -i contfix.co.il I get the enitre HTML and CSS of the webpage, That's basically all I get - tons of HTML and CSS. – JohnDoea Aug 14 '17 at 1:33
0

I had to put the cache expiration directive in the server block instead of the http block.

I Putted the code in the end of the site-conf server block, rstarted Nginx and GPI test no logner showed the notification.

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|ttf|woff)$ {
        expires 365d;
    }

    location ~*  \.(pdf)$ {
        expires 30d;
    }

} # domain.tld.conf server block closure.
  • How does this differ from your original configuration? When I look at that it looks like it's in the server block in the original config, and your answer. Would you mind clarifying? – Tim Aug 15 '17 at 7:46
  • I edited to make the answer more accurate and clear. – JohnDoea Aug 15 '17 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.