Posthog reverse proxy created following instructions from Posthog guide. Configurable.
751
A configurable nginx reverse proxy for PostHog that allows you to proxy requests to PostHog Cloud while maintaining security through referer header validation.
| Variable | Default | Required | Description |
|---|---|---|---|
NGINX_PORT | 8080 | No | Port on which nginx will listen |
DOMAIN | - | Yes | Your domain for referer validation (without protocol) |
POSTHOG_REGION | us | No | PostHog region (us or eu) |
# Build the image
docker build -t posthog-nginx-proxy .
# Run with required DOMAIN (will fail without it)
docker run -p 8080:8080 -e DOMAIN=myapp.com posthog-nginx-proxy
# Run with custom configuration
docker run -p 8080:8080 \
-e DOMAIN=myapp.com \
-e POSTHOG_REGION=eu \
-e NGINX_PORT=8080 \
posthog-nginx-proxy
version: '3.8'
services:
posthog-proxy:
build: .
ports:
- "8080:8080"
environment:
- DOMAIN=myapp.com
- POSTHOG_REGION=eu
- NGINX_PORT=8080
docker run -p 8080:8080 \
-e DOMAIN=myapp.com \
-e POSTHOG_REGION=us \
posthog-nginx-proxy
docker run -p 8080:8080 \
-e DOMAIN=myapp.com \
-e POSTHOG_REGION=eu \
posthog-nginx-proxy
docker run -p 9000:9000 \
-e NGINX_PORT=9000 \
-e DOMAIN=myapp.com \
posthog-nginx-proxy
Once your proxy is running, configure your PostHog client to use the proxy URL:
import posthog from 'posthog-js'
posthog.init('<your-project-api-key>', {
api_host: 'http://localhost:8080' // Your proxy URL
})
import posthog
posthog.api_key = '<your-project-api-key>'
posthog.host = 'http://localhost:8080' # Your proxy URL
This proxy includes referer header validation to ensure requests only come from your specified domain. The validation allows:
localhost (for development)app.myapp.com, www.myapp.com)Requests from other domains will receive a 403 Forbidden response.
Referer header to ensure requests come from your domain/static/* requests to PostHog's asset serversdocker build -t posthog-nginx-proxy .
# Start the proxy (DOMAIN is required)
docker run -p 8080:8080 -e DOMAIN=localhost posthog-nginx-proxy
# Test with curl
curl -H "Referer: http://localhost:8080" http://localhost:8080/capture
To see nginx logs:
docker run -p 8080:8080 -e DOMAIN=myapp.com posthog-nginx-proxy
This project is based on the PostHog nginx proxy documentation and is provided as-is for educational and development purposes.
Feel free to open issues or submit pull requests for improvements!
Content type
Image
Digest
sha256:19122dd7d…
Size
21.4 MB
Last updated
about 1 year ago
docker pull valian/posthog-nginx-proxy