Proxy DataFast with DigitalOcean

Learn how to proxy DataFast analytics through DigitalOcean to bypass adblockers and improve accuracy. This guide covers both App Platform and Droplet approaches.

Option 1: DigitalOcean App Platform

If you're using DigitalOcean App Platform with Node.js, follow the framework-specific guide based on your stack:

App Platform automatically handles IP forwarding through the X-Forwarded-For header, so the examples in those guides will work correctly.

Option 2: DigitalOcean Droplet with Nginx

If you're using a DigitalOcean Droplet with Nginx as your web server or reverse proxy, follow this configuration.

1. SSH into Your Droplet

ssh root@your-droplet-ip

2. Edit Nginx Configuration

Edit your site's Nginx configuration file (usually in /etc/nginx/sites-available/your-site):

sudo nano /etc/nginx/sites-available/your-site

3. Add Proxy Configuration

Add the following location blocks to your server configuration:

server {
    listen 80;
    server_name yourdomain.com;

    # Your existing configuration...

    # Proxy the analytics script
    location /js/script.js {
        proxy_pass https://datafa.st/js/script.js;
        proxy_set_header Host datafa.st;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        
        # Cache the script for 1 year
        add_header Cache-Control "public, max-age=31536000";
        expires 1y;
    }

    # Proxy the events endpoint
    location /api/events {
        proxy_pass https://datafa.st/api/events;
        proxy_set_header Host datafa.st;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        
        # Allow POST requests
        proxy_method POST;
        proxy_pass_request_body on;
    }

    # Your other location blocks...
}

Note: If you already have an /api/events location block, add data-api-url to the DataFast script tag. For example, data-api-url="/datafast-events" will send events to /datafast-events. Read more here

4. Test and Reload Nginx

Test the configuration for syntax errors:

sudo nginx -t

If the test passes, reload Nginx:

sudo systemctl reload nginx

5. Optional: Add Caching

For better performance, enable Nginx caching:

# Add this outside the server block (usually at the top of nginx.conf)
proxy_cache_path /var/cache/nginx/datafast_cache 
    levels=1:2 
    keys_zone=datafast_cache:10m 
    max_size=100m 
    inactive=60m 
    use_temp_path=off;

# In your server block, update the script location
location /js/script.js {
    proxy_cache datafast_cache;
    proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
    proxy_cache_valid 200 1y;
    proxy_cache_bypass $http_pragma;
    proxy_cache_revalidate on;
    
    proxy_pass https://datafa.st/js/script.js;
    proxy_set_header Host datafa.st;
    
    add_header Cache-Control "public, max-age=31536000";
    expires 1y;
}

Option 3: DigitalOcean Spaces CDN

If you're using DigitalOcean Spaces CDN in front of your Droplet, make sure to configure it to pass through the client IP:

  1. In your DigitalOcean dashboard, go to Networking > CDN
  2. Ensure your CDN is configured to forward headers
  3. The CDN automatically adds X-Forwarded-For headers
  4. Your Nginx configuration will pick up the IP from these headers

Update Your Script Tag

Replace your existing DataFast script with the proxied version:

<script
  defer
  data-website-id="dfid_******"
  data-domain="yourdomain.com"
  src="/js/script.js"
></script>

Verification

To verify the proxy is working:

  1. Visit your website
  2. Open the network tab in your browser's developer tools
  3. Check that analytics requests are going through your domain instead of datafa.st
  4. In your DataFast dashboard, verify that visitor locations are showing correctly

Troubleshooting

All visitors show the same location:

  • Verify $remote_addr is capturing the correct IP
  • If behind a load balancer, use $http_x_forwarded_for instead

502 Bad Gateway errors:

  • Ensure your Droplet can reach datafa.st (check firewall rules)
  • Verify SSL/TLS is working correctly
  • Check Nginx error logs: sudo tail -f /var/log/nginx/error.log

Need help with your DigitalOcean setup? Email us at marc@datafa.st

Something missing? Suggest features ✍️