Note: If you are using the EU cloud then use
eu
instead ofus
in all domains (e.g.us.i.posthog.com
->eu.i.posthog.com
)
You can use nginx as a reverse proxy. To do this, first create a Dockerfile
to build a nginx container:
FROM nginx:alpineCOPY nginx.conf /etc/nginx/nginx.conf
Next, create the nginx.conf
file with the reverse proxy configuration. The following checks the Referer
header to ensure the request is coming from your domain (set as hogbook.com
in this case), then proxies the request to PostHog Cloud US. Change us
to eu
to proxy to our EU Cloud.
# The main contextevents {worker_connections 1024;}http {server {listen 8080; # Set the port to 8080server_name _; # Accept requests for any domain# Check Referer header# Change hogbook to your domain as needed to ensure requests only come from your domainset $valid_referer 0;if ($http_referer ~* "^https?://(localhost|([a-zA-Z0-9-]+)\.hogbook\.com)") {set $valid_referer 1;}if ($valid_referer = 0) {return 403; # Return forbidden if the Referer header is invalid}location /static/ {proxy_pass https://us-assets.i.posthog.com/static/;proxy_set_header Host us-assets.i.posthog.com;}location / {proxy_pass https://us.i.posthog.com/;proxy_set_header Host us.i.posthog.com;}}}