跳至內容

Caching Conflict with AWS CloudFront for Multiple Subdomains

0

I have deployed multiple sites on AWS EC2 using different subdomains, and I'm using a single CloudFront distribution to serve content for all of these sites. However, I am encountering a caching conflict issue: For example, the following two images have the same path but are located on different subdomains:

https://site1.example.com/wp-content/uploads/2024/05/cta_bg.jpeg
https://site2.example.com/wp-content/uploads/2024/05/cta_bg.jpeg

Both URLs reference different images, yet they return the same cached image due to the identical path. How can I resolve this caching conflict and ensure that each image is served correctly based on its subdomain? Any guidance would be greatly appreciated!

已提問 2 年前檢視次數 625 次

2 個答案
3
已接受的答案

Hello,

To resolve the caching conflict in your CloudFront distribution while using multiple subdomains with the same URL paths, you can take the following approachs by using Cache Key Customization :

You can customize the cache key in CloudFront to include the subdomain as part of the cache key. This way, CloudFront will cache assets separately for each subdomain.

  • Steps to Customize Cache Key: 1- Open the CloudFront Console: Go to the AWS Management Console and open the CloudFront service.

    2- Select Your Distribution: Click on the distribution you want to modify.

    3- Edit Cache Behavior: In the "Behaviors" tab, select the cache behavior you want to modify, then click "Edit".

    4- Configure Cache Key Settings: Cache key and origin requests: Choose "Use a Cache Policy and Origin Request Policy". Cache Policy: Either create a new cache policy or modify an existing one. In the cache policy settings, ensure that you include the "Headers" option that specifies the Host header. This will differentiate cache entries based on the subdomain.

    5- Save Changes: After making the changes, save your settings.

By following the above steps, you can effectively customize the cache key in CloudFront to differentiate between resources served from different subdomains. This approach helps maintain the integrity of your content and ensures that each subdomain serves the correct resources without conflicts.

I hope this help !

Regards,

AWS

已回答 2 年前

專家

已審閱 2 年前

專家

已審閱 2 年前

0

I think you will need a separate CF distribution for each subdomain with its own custom domain and an origin pointing the corresponding EC2 instance.

AWS
專家

已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。