-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?

7
  • "to which I moved from Apache" means he moved from Apache to nginx. Aug 13, 2017 at 21:43
  • What is the complete default.conf? Aug 13, 2017 at 21:45
  • gist.github.com/Benqzq/5e21d720d0dbbc3ba94991ed5bd8ebb8
    – user329119
    Aug 13, 2017 at 22:53
  • 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, 2017 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.
    – user329119
    Aug 14, 2017 at 1:33

1 Answer 1

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.
2
  • 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, 2017 at 7:46
  • I edited to make the answer more accurate and clear.
    – user329119
    Aug 15, 2017 at 8:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .