There are some images in one site of mine which are hosted to a remote server. I haven't figured out yet how to set Cache-Control to remote sources. For local files I'm using:

location ~* \.(jpg|jpe?g|gif|png|ico|cur|gz|svgz|mp4|ogg|ogv|webm|htc|css|js|otf|eot|svg|ttf|woff|woff2)(\?ver=[0-9.]+)?$ {
    expires 1M;
    add_header Access-Control-Allow-Origin '*';
    add_header Pragma public;
    add_header Cache-Control "public, must-revalidate, proxy-revalidate";
    access_log off;

Which is working great.

I tried to add a location block containing the remote location of the files following the same principle with the local file, say for example https://example.com/img/ but nginx didnt do anything. The purpose of all this is to increase site speed.

Any suggestions will be appreciated.


You can't change the headers for remote resources by changing anything on your server. You need to change them on the server that's serving the files.

The only way I can think to achieve this would be to proxy the images through a dedicated path on your server, but that would require changing the HTML to point to that path.

  • in other words, to save the remote images to my server, then change the image path to my html. Correct? – Skeptic Sep 17 '16 at 17:40
  • Yes, that's correct. – Tim Sep 17 '16 at 18:25

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.