Stape/Documentation

How to use same origin through Apache HTTP Server

Updated Jan 16, 2026

If you're already running Apache HTTP Server as your main web server or reverse proxy, you can also configure it to proxy your server GTM request. Begin by adjusting your configuration, as shown in the next step.

This instruction uses /metrics as an example of the same origin path. You can use any of your own.

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

Step 1: Enable the required modules​

sudo a2enmod proxy sudo a2enmod proxy_httpsudo a2enmod ssl

Step 2: Update your config​

ServerName website.com ProxyRequests off ProxyPreserveHost off SSLProxyEngine on RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}e" RequestHeader set X-From-Cdn "cf‑stape" RequestHeader set CF-Connecting-Ip "%{REMOTE_ADDR}e" RequestHeader set Host "sgtm.example.com" ProxyPass "/metrics" "https://sgtm.example.com" ProxyPassReverse "/metrics" "https://sgtm.example.com"

Step 3: Adjust your deployed script

Deploy the changes to your site.

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.

If you are not using your own subdomain and are proxying requests to the standard Stape subdomain, you also need to add the X-Stape-Host header with the value of the host where the events are taking place (for instance, X-Stape-Hostwww.example.com).

Testing your Same Origin setup

You can check that everything is configured correctly by sending a single test request using a GA4 tag.

1. Create a GA4 tag in your web GTM container.

Add your Measurement ID (any ID works for testing) and set the server_container_url to the same-origin path you configured (we'll use https://stape.work/metrics as an example).

Test GA4 tag

2. (Optional) To streamline testing, add your same-origin path (in this example, it's https://stape.work/metrics) to your server GTM settings. Click Admin Container Settings → enter the path under Server container URLs.

Adding the same-origin path to container settings

3. Open Preview mode in both your web GTM container and your server-side GTM container. If everything is set up correctly, the server container should open in preview at the new path you created.

Preview opened at the new path

4. Trigger a page view on your site. In the server container preview, you should now see an incoming page_view request from your website’s real domain.

Incoming page_view request from your real domain

Comments

Can’t find what you are looking for?