Hi,
I'm trying to optimize a client's website on laravel and using Google's page speed, it keeps saying that I send no expiration date on the static files I send to the user.
So I tried to search how can I do that I found that I need to add some code in the nginx.conf. (https://www.howtoforge.com/make-browsers-cache-static-files-on-nginx)
So I went to the nginx.conf on my server and tried to add the following code
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
expires 4w;
}
They say I can add it inside the http{} or the server{}. Since there's no server{} in my nginx.conf file I tried to add it in the http one.
I also found a way to check if the file has really an expiration date with this command
curl -I http://www.mysite.com/picture.jpg
and I get this response
HTTP/1.1 200 OK
Server: nginx/1.8.0
Date: Tue, 22 Dec 2015 21:00:49 GMT
Content-Type: image/png
Content-Length: 7595
Last-Modified: Tue, 22 Dec 2015 18:07:53 GMT
Connection: keep-alive
ETag: "56799179-1dab"
Accept-Ranges: bytes
So no expiration date on the file. So I tried to change the place and created a server {}. (I also restarted each time nginx with sudo service nginx reload off course !) And I get the same answer no expiraction date on the file.
Am I doing something wrong, using the wrong code or adding the code at the wrong place, to tell nginx that I want him to send an expiration date !
Thanks in advance !