简体   繁体   中英

In AWS Cloudfront how to add cache-control?

I have setup my nopCommerce 4.10 (.net Core) in the Cloud Ec2 instance. And also setup the CDN CloudFront for it using a Load-balancer.

The main purpose of going to cloud and cdn was to improve the page speed for the client(the client asked for this).

Page speed after this has not improved and is showing that the image header has "cache policy" is not effective.

For this I need to set cache-control in the header. I checked the original image has this value but the load-balancer and cdn doesn't have this value for the images.

Please let me know how to set the cache-control in the header for CloudFront cdn.

Cache-control header should come from CloudFront Origin

(application that is behind Cloudfront).

Then cache-control header will be used by:

  • Cloudfront to cache objects in edge locations
  • User's browser, to cache objects directly in browser

In case of image, proper cache headers can be set in a place image is stored: S3 bucket, Apache config, etc..

Cloudfront does not strip cache headers, coming from origin. But your load balancer could. Open image via CloudFront Origin URL, to make sure headers are there.

Thanks for your response.

I think there was some issue with the load balancer configuration because of which this was happening to me.

After re-configuring the load balancer it has started to work.

You can now create a "Response headers policy"

Then, specify a custom header that is "Cache-Control" with the desired value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM