How can we help?

How to use same origin through AWS CloudFront

Uliana Lesiv
Uliana Lesiv
  • Updated

This guide uses /metrics as an example of a same-origin path, but you can use any path you choose.

You should also use the URL of your server GTM container instead of https://sgtm.example.com.

 

Step 1: Create a new origin

First, you need to create a new origin pointing to your server GTM container URL. In the CloudFront console, under your distribution, create a new origin:

  • Origin Domain Name: sgtm.example.com
  • Origin Protocol Policy: HTTPS Only

 

Step 2: Create custom behaviors

Then, define some custom behavior for when to use your new origin. In the CloudFront console, under your distribution, create new behavior.

  • Path Pattern: /metrics
  • Origin or Origin Group: The origin we created in step 1
  • Viewer Protocol Policy: HTTPS Only
  • Allowed HTTP Methods: GET, HEAD, OPTIONS, PUT, POST, PATCH, DELETE
  • Origin Request Policy: Managed-UserAgentRefererHeaders

 

Under Origin Custom Headers, click Add Custom Header:

Name: X-From-Cdn

Value: f-stape

Under Origin Custom Headers, click Add Custom Header:

Name: Host

Value: sgtm.example.com

 

Step 3: Adjust your deployed script

Deploy these changes to your CloudFront site.

You can verify the proxy is working by opening your proxy path in the browser. Go to https://sgtm.example.com/metrics. If you see error 400, then everything is working correctly. You can also run a preview of the server container on your /metrics path.

 

After following these steps, add your /path for the same origin to the Custom Loader's settings. Check the article on Same Origin Path to do this.

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.