Install DataPocket on NGINX

Updated

Two location blocks in your server config. Sign in and these snippets fill in your site ID and domain. Until then, swap YOUR_SITE_ID and YOUR_DOMAIN with the values from your Install page.

  1. 1

    Inside your server { } block:

    nginx
    location ~ ^/dp/js/(script(\.[a-z]+)?(@\d+\.\d+\.\d+)?\.js)$ {
        proxy_pass https://datapocket.vo1d.studio/js/$1;
        proxy_set_header Host datapocket.vo1d.studio;
        proxy_set_header Cookie "";
        proxy_set_header Authorization "";
        proxy_ssl_server_name on;
        proxy_hide_header Set-Cookie;
    }
    
    location = /dp/api/event {
        proxy_pass https://datapocket.vo1d.studio/api/event;
        proxy_set_header Host datapocket.vo1d.studio;
        proxy_set_header X-Forwarded-For $remote_addr;
        # proxy_pass forwards every request header: drop the visitor's cookies and credentials
        proxy_set_header Cookie "";
        proxy_set_header Authorization "";
        proxy_ssl_server_name on;
        proxy_hide_header Set-Cookie;
    }
  2. 2

    Reload (nginx -t && nginx -s reload), then:

    html
    <script
      defer
      data-site-id="YOUR_SITE_ID"
      data-domain="YOUR_DOMAIN"
      src="/dp/js/script.js"
    ></script>
  3. 3

    Behind Cloudflare or a load balancer? Enable the realip module (set_real_ip_from + real_ip_header X-Forwarded-For) so $remote_addr is the visitor's IP.

Related guides

Install DataPocket on NGINX · DataPocket