plausible / analytics

Simple, open source, lightweight (< 1 KB) and privacy-friendly web analytics alternative to Google Analytics.
https://plausible.io
GNU Affero General Public License v3.0
20.42k stars 1.09k forks source link

Cloudflare Workers not work with Countries #3976

Closed viriatusX closed 7 months ago

viriatusX commented 7 months ago

Past Issues Searched

Issue is a Bug Report

Using official Plausible Cloud hosting or self-hosting?

Self-hosting

Describe the bug

When you enable the Plausible method with Cloudflare workers (https://plausible.io/docs/proxy/guides/cloudflare). It does not update the visitors' country map in the UI.

Expected behavior

Plausible should update the UI, the visitor map by country, by having CloudFlare workers enabled.

Screenshots

No response

Environment

No response

ruslandoga commented 7 months ago

👋 @viriatusX

The last time I tried cf workers, everything was working as expected: https://github.com/plausible/analytics/discussions/2137#discussioncomment-6349831

Could you please share more of your setup?

viriatusX commented 7 months ago

Hi @ruslandoga

All statistics are displayed correctly, except the Map with the country / region / city of the visitors. It does not show anything. When I deactivate the Worker, everything works perfectly.

I have Plausible with Nginx Proxy Manager (without additional HTTP headers. I have the Plausible domain as "Proxied". I have tried with Plausible remote: iex> Plausible.Geo.lookup("1.1.1.1.1") And it shows the country and everything ok.

The problem is that it is not reflected in the UI.

ruslandoga commented 7 months ago

Would you be able to share your configuration files, including nginx, worker scripts, and anything else that seems relevant?

ruslandoga commented 7 months ago

You can also trace the incoming request to see what headers are included with recon_trace. There have been several discussions where it helped resolve IP geo location issues. https://github.com/plausible/analytics/discussions/3248#discussioncomment-6670217 https://github.com/plausible/analytics/discussions/2767#discussioncomment-5367417 etc. (you can search for others using parts of that code snippet)

viriatusX commented 7 months ago

I have executed this inside Plausible remote. But I don't know how to check it with my domain. Sorry.

iex> headers = fn {:trace, _pid, :call, {_mod, _fun, [%Plug.Conn{req_headers: headers}]}} -> inspect(headers) end
iex> mod_fun_args = {PlausibleWeb.RemoteIp, :get, 1}
iex> how_many_times = 5
iex> :recon_trace.calls(mod_fun_args, how_many_times, formatter: headers)

My Worker Script is the same of yours (changing only my domain).

My Nginx conf for the Plausible domain:

# ------------------------------------------------------------
# stats.xxxxx.com
# ------------------------------------------------------------

server {
  set $forward_scheme http;
  set $server         "192.168.10.165";
  set $port           3998;

  listen 80;
listen [::]:80;

listen 443 ssl http2;
listen [::]:443 ssl http2;

  server_name xxxxx.com;

  # Let's Encrypt SSL
  include conf.d/include/letsencrypt-acme-challenge.conf;
  include conf.d/include/ssl-ciphers.conf;
  ssl_certificate /etc/letsencrypt/live/npm-23/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/npm-23/privkey.pem;

proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
proxy_http_version 1.1;

  access_log /data/logs/proxy-host-15_access.log proxy;
  error_log /data/logs/proxy-host-15_error.log warn;

  location / {

    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $http_connection;
    proxy_http_version 1.1;

    # Proxy!
    include conf.d/include/proxy.conf;
  }

  # Custom
  include /data/nginx/custom/server_proxy[.]conf;
}
viriatusX commented 7 months ago

I execute Plausible GeoIP command with this IP, but in the UI not appear... with Workers enabled.

Captura de pantalla 2024-04-04 a las 23 18 26 Captura de pantalla 2024-04-04 a las 23 18 34
viriatusX commented 7 months ago

Ant the output for this command (in case it helps.)

Captura de pantalla 2024-04-04 a las 23 20 27
ruslandoga commented 7 months ago

I have executed this inside Plausible remote. But I don't know how to check it with my domain. Sorry.

You would need to visit your site which would make an /api/event call. The traces would be printed in the console. Ideally, you'd run it both when the Worker is activated and when it's not.

ruslandoga commented 7 months ago

All statistics are displayed correctly, except the Map with the country / region / city of the visitors. It does not show anything. When I deactivate the Worker, everything works perfectly.

I've re-read this now, and it's not clear what exactly is wrong, is the map empty or not displayed at all? Can you show screenshot for when the Worker is activated and when it's not?

viriatusX commented 7 months ago

If I access with an IP from Portugal:

With Worker

<img width="532" alt="Captura de pantalla 20" src="https://github.com/plausible/analytics/assets/64467637/bab13a7e-7014-48b5-9d06-4fdd6f0d6820">

Without Worker

Captura de pantalla 2024-04-05 a las 11 37 17

The map is not updated. The rest of the statistics work OK. If it was a /api/event problem, I think it would not show any statistics.

ruslandoga commented 7 months ago

Great, then https://github.com/plausible/analytics/issues/3976#issuecomment-2039307082 should help resolve it. Most likely, the X-Forwarded-For header or similar is dropped somewhere along the way. You can also trace Plausible.Geo.lookup to see what exact IP address is used for the lookup of your Portugal request and what info it gets in return.

viriatusX commented 7 months ago

Great, then #3976 (comment) should help resolve it. Most likely, the X-Forwarded-For header or similar is dropped somewhere along the way. You can also trace Plausible.Geo.lookup to see what exact IP address is used for the lookup of your Portugal request and what info it gets in return.

Thanks for your help. Forgive my clumsiness. I have executed this, but then I don't know how to continue.

iex> headers = fn {:trace, _pid, :call, {_mod, _fun, [%Plug.Conn{req_headers: headers}]}} -> inspect(headers) end
iex> mod_fun_args = {PlausibleWeb.RemoteIp, :get, 1}
iex> how_many_times = 5
iex> :recon_trace.calls(mod_fun_args, how_many_times, formatter: headers)
ruslandoga commented 7 months ago

I have executed this, but then I don't know how to continue.

You would need to visit https://hdsplus.co after you run these commands. The traces would be printed in the console. Ideally, you'd run it both when the Worker is activated and when it's not.

You can check the previous discussions I linked for more info :) E.g. https://github.com/plausible/analytics/discussions/2767#discussioncomment-5367417

viriatusX commented 7 months ago

Sorry, on which console do I view the trace? The Plausible console does not show anything new.

  1. I execute these commands
  2. I access to my Web with Chrome and Safari
Captura de pantalla 2024-04-05 a las 12 04 43
ruslandoga commented 7 months ago

If it doesn't show anything, then there are no requests reaching Plausible. Try running it with the Worker deactivated.

viriatusX commented 7 months ago

Neither... The Plausible remote console does not show anything new after executing these commands. And without Worker everything works fine. Strange.

ruslandoga commented 7 months ago

Ok, I see. I guess you are on v2.1.0-rc.0? The module name changed from RemoteIp to RemoteIP in https://github.com/plausible/analytics/pull/3761. Please run this command instead :recon_trace.calls({PlausibleWeb.RemoteIP, :get, 1}, 10)

viriatusX commented 7 months ago

Thanks! now yes!

ruslandoga commented 7 months ago

Please post the traces as code or text snippet. It would be easier to debug.

viriatusX commented 7 months ago

With Worker OFF

10:51:03.834035 <0.10238.0> 'Elixir.PlausibleWeb.RemoteIP':get(#{owner=><0.10238.0>, port=>80, private=>#{'Elixir.PlausibleWeb.Router'=>[], phoenix_view=>#{'_'=>'Elixir.PlausibleWeb.Api.ExternalView'}, plug_session_fetch=>done, plug_session=>#{}, before_send=>[#Fun<Elixir.Plug.Session.0.76384852>,#Fun<Elixir.Plug.Telemetry.0.54455629>], phoenix_endpoint=>'Elixir.PlausibleWeb.Endpoint', phoenix_action=>event, phoenix_layout=>#{'_'=>{'Elixir.PlausibleWeb.LayoutView',app}}, phoenix_controller=>'Elixir.PlausibleWeb.Api.ExternalController', phoenix_format=><<"json">>, phoenix_router=>'Elixir.PlausibleWeb.Router'}, scheme=>http, status=>nil, script_name=>[], state=>unset, host=><<"stats.hdsplus.co">>, cookies=>#{}, params=>#{}, '__struct__'=>'Elixir.Plug.Conn', halted=>false, assigns=>#{}, method=><<"POST">>, adapter=>{'Elixir.Plug.Cowboy.Conn',#{pid => <0.10237.0>,port => 80,
                             scheme => <<"http">>,version => 'HTTP/1.1',
                             path => <<"/api/event">>,
                             host => <<"stats.hdsplus.co">>,
                             peer => {{192,168,144,1},59938},
                             sock => {{192,168,144,2},8000},
                             bindings => #{},
                             ref => 'Elixir.PlausibleWeb.Endpoint.HTTP',
                             cert => undefined,
                             headers =>
                                 #{<<"accept">> => <<"*/*">>,
                                   <<"accept-encoding">> => <<"gzip, br">>,
                                   <<"accept-language">> =>
                                       <<"es-ES,es;q=0.9,en;q=0.8,ca;q=0.7,zh-CN;q=0.6,zh;q=0.5">>,
                                   <<"cdn-loop">> => <<"cloudflare">>,
                                   <<"cf-ipcontinent">> => <<"EU">>,
                                   <<"cf-ipcountry">> => <<"ES">>,
                                   <<"cf-iplatitude">> => <<"41.39490">>,
                                   <<"cf-iplongitude">> => <<"2.17560">>,
                                   <<"cf-ray">> => <<"86f8fb147d571511-MAD">>,
                                   <<"cf-region">> => <<"Catalonia">>,
                                   <<"cf-region-code">> => <<"CT">>,
                                   <<"cf-timezone">> => <<"Europe/Madrid">>,
                                   <<"cf-visitor">> =>
                                       <<"{\"scheme\":\"https\"}">>,
                                   <<"content-length">> => <<"74">>,
                                   <<"content-type">> => <<"text/plain">>,
                                   <<"host">> => <<"stats.hdsplus.co">>,
                                   <<"origin">> => <<"https://hdsplus.co">>,
                                   <<"priority">> => <<"u=1, i">>,
                                   <<"referer">> => <<"https://hdsplus.co/">>,
                                   <<"sec-ch-ua">> =>
                                       <<"\"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"">>,
                                   <<"sec-ch-ua-mobile">> => <<"?0">>,
                                   <<"sec-ch-ua-platform">> => <<"\"macOS\"">>,
                                   <<"sec-fetch-dest">> => <<"empty">>,
                                   <<"sec-fetch-mode">> => <<"cors">>,
                                   <<"sec-fetch-site">> => <<"same-site">>,
                                   <<"user-agent">> =>
                                       <<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36">>,
                                   <<"x-forwarded-for">> =>
                                       <<"83.44.134.248, 188.114.111.124">>,
                                   <<"x-forwarded-proto">> => <<"https">>,
                                   <<"x-forwarded-scheme">> => <<"https">>,
                                   <<"x-real-ip">> => <<"188.114.111.124">>},
                             method => <<"POST">>,qs => <<>>,
                             path_info => undefined,streamid => 1,
                             body_length => 74,has_body => true,
                             host_info => undefined}}, secret_key_base=><<"jMI5V6xYzyfwHSHhYnluvqHKa69CdX7XOyKeh925wAOrpaq7yaZLQEovqh2mJJrbnuXSGZ0k0rHY0VxaQ4Q//w==">>, body_params=>#{'__struct__'=>'Elixir.Plug.Conn.Unfetched', aspect=>body_params}, path_info=>[<<"api">>,<<"event">>], path_params=>#{}, query_params=>#{}, query_string=><<>>, remote_ip=>{192,168,144,1}, req_cookies=>#{}, req_headers=>[{<<"accept">>,<<"*/*">>},
 {<<"accept-encoding">>,<<"gzip, br">>},
 {<<"accept-language">>,
  <<"es-ES,es;q=0.9,en;q=0.8,ca;q=0.7,zh-CN;q=0.6,zh;q=0.5">>},
 {<<"cdn-loop">>,<<"cloudflare">>},
 {<<"cf-ipcontinent">>,<<"EU">>},
 {<<"cf-ipcountry">>,<<"ES">>},
 {<<"cf-iplatitude">>,<<"41.39490">>},
 {<<"cf-iplongitude">>,<<"2.17560">>},
 {<<"cf-ray">>,<<"86f8fb147d571511-MAD">>},
 {<<"cf-region">>,<<"Catalonia">>},
 {<<"cf-region-code">>,<<"CT">>},
 {<<"cf-timezone">>,<<"Europe/Madrid">>},
 {<<"cf-visitor">>,<<"{\"scheme\":\"https\"}">>},
 {<<"content-length">>,<<"74">>},
 {<<"content-type">>,<<"text/plain">>},
 {<<"host">>,<<"stats.hdsplus.co">>},
 {<<"origin">>,<<"https://hdsplus.co">>},
 {<<"priority">>,<<"u=1, i">>},
 {<<"referer">>,<<"https://hdsplus.co/">>},
 {<<"sec-ch-ua">>,
  <<"\"Google Chrome\";v=\"123\", \"Not:A-Brand\";v=\"8\", \"Chromium\";v=\"123\"">>},
 {<<"sec-ch-ua-mobile">>,<<"?0">>},
 {<<"sec-ch-ua-platform">>,<<"\"macOS\"">>},
 {<<"sec-fetch-dest">>,<<"empty">>},
 {<<"sec-fetch-mode">>,<<"cors">>},
 {<<"sec-fetch-site">>,<<"same-site">>},
 {<<"user-agent">>,
  <<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36">>},
 {<<"x-forwarded-for">>,<<"83.44.134.248, 188.114.111.124">>},
 {<<"x-forwarded-proto">>,<<"https">>},
 {<<"x-forwarded-scheme">>,<<"https">>},
 {<<"x-real-ip">>,<<"188.114.111.124">>}], request_path=><<"/api/event">>, resp_body=>nil, resp_cookies=>#{}, resp_headers=>[{<<"cache-control">>,<<"max-age=0, private, must-revalidate">>},
 {<<"x-request-id">>,<<"F8NcwC-h5A2dSpEAAOWC">>},
 {<<"access-control-allow-credentials">>,<<"true">>},
 {<<"access-control-allow-origin">>,<<"*">>},
 {<<"access-control-expose-headers">>,<<>>}]})

With Worker ON

10:49:58.276958 <0.10200.0> 'Elixir.PlausibleWeb.RemoteIP':get(#{owner=><0.10200.0>, port=>80, private=>#{'Elixir.PlausibleWeb.Router'=>[], phoenix_view=>#{'_'=>'Elixir.PlausibleWeb.Api.ExternalView'}, plug_session_fetch=>done, plug_session=>#{}, before_send=>[#Fun<Elixir.Plug.Session.0.76384852>,#Fun<Elixir.Plug.Telemetry.0.54455629>], phoenix_endpoint=>'Elixir.PlausibleWeb.Endpoint', phoenix_action=>event, phoenix_layout=>#{'_'=>{'Elixir.PlausibleWeb.LayoutView',app}}, phoenix_controller=>'Elixir.PlausibleWeb.Api.ExternalController', phoenix_format=><<"json">>, phoenix_router=>'Elixir.PlausibleWeb.Router'}, scheme=>http, status=>nil, script_name=>[], state=>unset, host=><<"stats.hdsplus.co">>, cookies=>#{}, params=>#{}, '__struct__'=>'Elixir.Plug.Conn', halted=>false, assigns=>#{}, method=><<"POST">>, adapter=>{'Elixir.Plug.Cowboy.Conn',#{pid => <0.10199.0>,port => 80,
                             scheme => <<"http">>,version => 'HTTP/1.1',
                             path => <<"/api/event">>,
                             host => <<"stats.hdsplus.co">>,
                             peer => {{192,168,144,1},54410},
                             sock => {{192,168,144,2},8000},
                             bindings => #{},
                             ref => 'Elixir.PlausibleWeb.Endpoint.HTTP',
                             cert => undefined,
                             headers =>
                                 #{<<"accept">> => <<"*/*">>,
                                   <<"accept-encoding">> => <<"gzip">>,
                                   <<"accept-language">> =>
                                       <<"es-ES,es;q=0.9">>,
                                   <<"cdn-loop">> =>
                                       <<"cloudflare; subreqs=1">>,
                                   <<"cf-ew-via">> => <<"15">>,
                                   <<"cf-ipcity">> => <<"El Astillero">>,
                                   <<"cf-ipcontinent">> => <<"EU">>,
                                   <<"cf-ipcountry">> => <<"ES">>,
                                   <<"cf-iplatitude">> => <<"43.40160">>,
                                   <<"cf-iplongitude">> => <<"-3.81530">>,
                                   <<"cf-postal-code">> => <<"39610">>,
                                   <<"cf-ray">> => <<"86f8f97ad3bb69eb-MAD">>,
                                   <<"cf-region">> => <<"Cantabria">>,
                                   <<"cf-region-code">> => <<"CB">>,
                                   <<"cf-timezone">> => <<"Europe/Madrid">>,
                                   <<"cf-visitor">> =>
                                       <<"{\"scheme\":\"https\"}">>,
                                   <<"cf-worker">> =>
                                       <<"hdsplus.workers.dev">>,
                                   <<"content-length">> => <<"125">>,
                                   <<"content-type">> => <<"text/plain">>,
                                   <<"host">> => <<"stats.hdsplus.co">>,
                                   <<"origin">> => <<"https://hdsplus.co">>,
                                   <<"priority">> => <<"u=3, i">>,
                                   <<"referer">> => <<"https://hdsplus.co/">>,
                                   <<"sec-fetch-dest">> => <<"empty">>,
                                   <<"sec-fetch-mode">> => <<"cors">>,
                                   <<"sec-fetch-site">> => <<"cross-site">>,
                                   <<"user-agent">> =>
                                       <<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15">>,
                                   <<"x-forwarded-for">> =>
                                       <<"2a06:98c0:3600::103, 172.70.57.158">>,
                                   <<"x-forwarded-proto">> => <<"https">>,
                                   <<"x-forwarded-scheme">> => <<"https">>,
                                   <<"x-real-ip">> => <<"172.70.57.158">>},
                             method => <<"POST">>,qs => <<>>,
                             path_info => undefined,streamid => 1,
                             body_length => 125,has_body => true,
                             host_info => undefined}}, secret_key_base=><<"jMI5V6xYzyfwHSHhYnluvqHKa69CdX7XOyKeh925wAOrpaq7yaZLQEovqh2mJJrbnuXSGZ0k0rHY0VxaQ4Q//w==">>, body_params=>#{'__struct__'=>'Elixir.Plug.Conn.Unfetched', aspect=>body_params}, path_info=>[<<"api">>,<<"event">>], path_params=>#{}, query_params=>#{}, query_string=><<>>, remote_ip=>{192,168,144,1}, req_cookies=>#{}, req_headers=>[{<<"accept">>,<<"*/*">>},
 {<<"accept-encoding">>,<<"gzip">>},
 {<<"accept-language">>,<<"es-ES,es;q=0.9">>},
 {<<"cdn-loop">>,<<"cloudflare; subreqs=1">>},
 {<<"cf-ew-via">>,<<"15">>},
 {<<"cf-ipcity">>,<<"El Astillero">>},
 {<<"cf-ipcontinent">>,<<"EU">>},
 {<<"cf-ipcountry">>,<<"ES">>},
 {<<"cf-iplatitude">>,<<"43.40160">>},
 {<<"cf-iplongitude">>,<<"-3.81530">>},
 {<<"cf-postal-code">>,<<"39610">>},
 {<<"cf-ray">>,<<"86f8f97ad3bb69eb-MAD">>},
 {<<"cf-region">>,<<"Cantabria">>},
 {<<"cf-region-code">>,<<"CB">>},
 {<<"cf-timezone">>,<<"Europe/Madrid">>},
 {<<"cf-visitor">>,<<"{\"scheme\":\"https\"}">>},
 {<<"cf-worker">>,<<"hdsplus.workers.dev">>},
 {<<"content-length">>,<<"125">>},
 {<<"content-type">>,<<"text/plain">>},
 {<<"host">>,<<"stats.hdsplus.co">>},
 {<<"origin">>,<<"https://hdsplus.co">>},
 {<<"priority">>,<<"u=3, i">>},
 {<<"referer">>,<<"https://hdsplus.co/">>},
 {<<"sec-fetch-dest">>,<<"empty">>},
 {<<"sec-fetch-mode">>,<<"cors">>},
 {<<"sec-fetch-site">>,<<"cross-site">>},
 {<<"user-agent">>,
  <<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15">>},
 {<<"x-forwarded-for">>,<<"2a06:98c0:3600::103, 172.70.57.158">>},
 {<<"x-forwarded-proto">>,<<"https">>},
 {<<"x-forwarded-scheme">>,<<"https">>},
 {<<"x-real-ip">>,<<"172.70.57.158">>}], request_path=><<"/api/event">>, resp_body=>nil, resp_cookies=>#{}, resp_headers=>[{<<"cache-control">>,<<"max-age=0, private, must-revalidate">>},
 {<<"x-request-id">>,<<"F8NcsOwkU1YbXDIAAbSB">>},
 {<<"access-control-allow-credentials">>,<<"true">>},
 {<<"access-control-allow-origin">>,<<"*">>},
 {<<"access-control-expose-headers">>,<<>>}]})
ruslandoga commented 7 months ago

x-forwarded-for are completely different. Are both of these your own requests or real users? Either way, Plausible is picking the first IP address in the x-forwarded-for list, which is different from x-real-ip (whatever it is) which is the last element in the x-forwarded-for list. According to https://en.wikipedia.org/wiki/X-Forwarded-For, the client IP address is the first element in the list, so Plausible is correct, at least according to Wikipedia.

viriatusX commented 7 months ago

Yes. I tried again:

WORKER OFF

11:4:44.229315 <0.10633.0> 'Elixir.PlausibleWeb.RemoteIP':get(#{owner=><0.10633.0>, port=>80, private=>#{'Elixir.PlausibleWeb.Router'=>[], phoenix_view=>#{'_'=>'Elixir.PlausibleWeb.Api.ExternalView'}, plug_session_fetch=>done, plug_session=>#{}, before_send=>[#Fun<Elixir.Plug.Session.0.76384852>,#Fun<Elixir.Plug.Telemetry.0.54455629>], phoenix_endpoint=>'Elixir.PlausibleWeb.Endpoint', phoenix_action=>event, phoenix_layout=>#{'_'=>{'Elixir.PlausibleWeb.LayoutView',app}}, phoenix_controller=>'Elixir.PlausibleWeb.Api.ExternalController', phoenix_format=><<"json">>, phoenix_router=>'Elixir.PlausibleWeb.Router'}, scheme=>http, status=>nil, script_name=>[], state=>unset, host=><<"stats.hdsplus.co">>, cookies=>#{}, params=>#{}, '__struct__'=>'Elixir.Plug.Conn', halted=>false, assigns=>#{}, method=><<"POST">>, adapter=>{'Elixir.Plug.Cowboy.Conn',#{pid => <0.10632.0>,port => 80,
                             scheme => <<"http">>,version => 'HTTP/1.1',
                             path => <<"/api/event">>,
                             host => <<"stats.hdsplus.co">>,
                             peer => {{192,168,144,1},60416},
                             sock => {{192,168,144,2},8000},
                             bindings => #{},
                             ref => 'Elixir.PlausibleWeb.Endpoint.HTTP',
                             cert => undefined,
                             headers =>
                                 #{<<"accept">> => <<"*/*">>,
                                   <<"accept-encoding">> => <<"gzip, br">>,
                                   <<"accept-language">> =>
                                       <<"es-ES,es;q=0.9">>,
                                   <<"cdn-loop">> => <<"cloudflare">>,
                                   <<"cf-ipcontinent">> => <<"EU">>,
                                   <<"cf-ipcountry">> => <<"ES">>,
                                   <<"cf-iplatitude">> => <<"41.39490">>,
                                   <<"cf-iplongitude">> => <<"2.17560">>,
                                   <<"cf-ray">> => <<"86f90f1c0af68686-MAD">>,
                                   <<"cf-region">> => <<"Catalonia">>,
                                   <<"cf-region-code">> => <<"CT">>,
                                   <<"cf-timezone">> => <<"Europe/Madrid">>,
                                   <<"cf-visitor">> =>
                                       <<"{\"scheme\":\"https\"}">>,
                                   <<"content-length">> => <<"74">>,
                                   <<"content-type">> => <<"text/plain">>,
                                   <<"host">> => <<"stats.hdsplus.co">>,
                                   <<"origin">> => <<"https://hdsplus.co">>,
                                   <<"priority">> => <<"u=3, i">>,
                                   <<"referer">> => <<"https://hdsplus.co/">>,
                                   <<"sec-fetch-dest">> => <<"empty">>,
                                   <<"sec-fetch-mode">> => <<"cors">>,
                                   <<"sec-fetch-site">> => <<"same-site">>,
                                   <<"user-agent">> =>
                                       <<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15">>,
                                   <<"x-forwarded-for">> =>
                                       <<"83.44.134.248, 172.64.236.58">>,
                                   <<"x-forwarded-proto">> => <<"https">>,
                                   <<"x-forwarded-scheme">> => <<"https">>,
                                   <<"x-real-ip">> => <<"172.64.236.58">>},
                             method => <<"POST">>,qs => <<>>,
                             path_info => undefined,streamid => 1,
                             body_length => 74,has_body => true,
                             host_info => undefined}}, secret_key_base=><<"jMI5V6xYzyfwHSHhYnluvqHKa69CdX7XOyKeh925wAOrpaq7yaZLQEovqh2mJJrbnuXSGZ0k0rHY0VxaQ4Q//w==">>, body_params=>#{'__struct__'=>'Elixir.Plug.Conn.Unfetched', aspect=>body_params}, path_info=>[<<"api">>,<<"event">>], path_params=>#{}, query_params=>#{}, query_string=><<>>, remote_ip=>{192,168,144,1}, req_cookies=>#{}, req_headers=>[{<<"accept">>,<<"*/*">>},
 {<<"accept-encoding">>,<<"gzip, br">>},
 {<<"accept-language">>,<<"es-ES,es;q=0.9">>},
 {<<"cdn-loop">>,<<"cloudflare">>},
 {<<"cf-ipcontinent">>,<<"EU">>},
 {<<"cf-ipcountry">>,<<"ES">>},
 {<<"cf-iplatitude">>,<<"41.39490">>},
 {<<"cf-iplongitude">>,<<"2.17560">>},
 {<<"cf-ray">>,<<"86f90f1c0af68686-MAD">>},
 {<<"cf-region">>,<<"Catalonia">>},
 {<<"cf-region-code">>,<<"CT">>},
 {<<"cf-timezone">>,<<"Europe/Madrid">>},
 {<<"cf-visitor">>,<<"{\"scheme\":\"https\"}">>},
 {<<"content-length">>,<<"74">>},
 {<<"content-type">>,<<"text/plain">>},
 {<<"host">>,<<"stats.hdsplus.co">>},
 {<<"origin">>,<<"https://hdsplus.co">>},
 {<<"priority">>,<<"u=3, i">>},
 {<<"referer">>,<<"https://hdsplus.co/">>},
 {<<"sec-fetch-dest">>,<<"empty">>},
 {<<"sec-fetch-mode">>,<<"cors">>},
 {<<"sec-fetch-site">>,<<"same-site">>},
 {<<"user-agent">>,
  <<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15">>},
 {<<"x-forwarded-for">>,<<"83.44.134.248, 172.64.236.58">>},
 {<<"x-forwarded-proto">>,<<"https">>},
 {<<"x-forwarded-scheme">>,<<"https">>},
 {<<"x-real-ip">>,<<"172.64.236.58">>}], request_path=><<"/api/event">>, resp_body=>nil, resp_cookies=>#{}, resp_headers=>[{<<"cache-control">>,<<"max-age=0, private, must-revalidate">>},
 {<<"x-request-id">>,<<"F8NdfzMB-RhBddoAAPeC">>},
 {<<"access-control-allow-credentials">>,<<"true">>},
 {<<"access-control-allow-origin">>,<<"*">>},
 {<<"access-control-expose-headers">>,<<>>}]})

WORKER ON

11:5:07.657798 <0.10637.0> 'Elixir.PlausibleWeb.RemoteIP':get(#{owner=><0.10637.0>, port=>80, private=>#{'Elixir.PlausibleWeb.Router'=>[], phoenix_view=>#{'_'=>'Elixir.PlausibleWeb.Api.ExternalView'}, plug_session_fetch=>done, plug_session=>#{}, before_send=>[#Fun<Elixir.Plug.Session.0.76384852>,#Fun<Elixir.Plug.Telemetry.0.54455629>], phoenix_endpoint=>'Elixir.PlausibleWeb.Endpoint', phoenix_action=>event, phoenix_layout=>#{'_'=>{'Elixir.PlausibleWeb.LayoutView',app}}, phoenix_controller=>'Elixir.PlausibleWeb.Api.ExternalController', phoenix_format=><<"json">>, phoenix_router=>'Elixir.PlausibleWeb.Router'}, scheme=>http, status=>nil, script_name=>[], state=>unset, host=><<"stats.hdsplus.co">>, cookies=>#{}, params=>#{}, '__struct__'=>'Elixir.Plug.Conn', halted=>false, assigns=>#{}, method=><<"POST">>, adapter=>{'Elixir.Plug.Cowboy.Conn',#{pid => <0.10636.0>,port => 80,
                             scheme => <<"http">>,version => 'HTTP/1.1',
                             path => <<"/api/event">>,
                             host => <<"stats.hdsplus.co">>,
                             peer => {{192,168,144,1},38690},
                             sock => {{192,168,144,2},8000},
                             bindings => #{},
                             ref => 'Elixir.PlausibleWeb.Endpoint.HTTP',
                             cert => undefined,
                             headers =>
                                 #{<<"accept">> => <<"*/*">>,
                                   <<"accept-encoding">> => <<"gzip">>,
                                   <<"accept-language">> =>
                                       <<"es-ES,es;q=0.9">>,
                                   <<"cdn-loop">> =>
                                       <<"cloudflare; subreqs=1">>,
                                   <<"cf-ew-via">> => <<"15">>,
                                   <<"cf-ipcontinent">> => <<"EU">>,
                                   <<"cf-ipcountry">> => <<"ES">>,
                                   <<"cf-iplatitude">> => <<"41.39490">>,
                                   <<"cf-iplongitude">> => <<"2.17560">>,
                                   <<"cf-ray">> => <<"86f90fae53e85e5c-MAD">>,
                                   <<"cf-region">> => <<"Catalonia">>,
                                   <<"cf-region-code">> => <<"CT">>,
                                   <<"cf-timezone">> => <<"Europe/Madrid">>,
                                   <<"cf-visitor">> =>
                                       <<"{\"scheme\":\"https\"}">>,
                                   <<"cf-worker">> =>
                                       <<"hdsplus.workers.dev">>,
                                   <<"content-length">> => <<"74">>,
                                   <<"content-type">> => <<"text/plain">>,
                                   <<"host">> => <<"stats.hdsplus.co">>,
                                   <<"origin">> => <<"https://hdsplus.co">>,
                                   <<"priority">> => <<"u=3, i">>,
                                   <<"referer">> => <<"https://hdsplus.co/">>,
                                   <<"sec-fetch-dest">> => <<"empty">>,
                                   <<"sec-fetch-mode">> => <<"cors">>,
                                   <<"sec-fetch-site">> => <<"cross-site">>,
                                   <<"user-agent">> =>
                                       <<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15">>,
                                   <<"x-forwarded-for">> =>
                                       <<"2a06:98c0:3600::103, 188.114.111.178">>,
                                   <<"x-forwarded-proto">> => <<"https">>,
                                   <<"x-forwarded-scheme">> => <<"https">>,
                                   <<"x-real-ip">> => <<"188.114.111.178">>},
                             method => <<"POST">>,qs => <<>>,
                             path_info => undefined,streamid => 1,
                             body_length => 74,has_body => true,
                             host_info => undefined}}, secret_key_base=><<"jMI5V6xYzyfwHSHhYnluvqHKa69CdX7XOyKeh925wAOrpaq7yaZLQEovqh2mJJrbnuXSGZ0k0rHY0VxaQ4Q//w==">>, body_params=>#{'__struct__'=>'Elixir.Plug.Conn.Unfetched', aspect=>body_params}, path_info=>[<<"api">>,<<"event">>], path_params=>#{}, query_params=>#{}, query_string=><<>>, remote_ip=>{192,168,144,1}, req_cookies=>#{}, req_headers=>[{<<"accept">>,<<"*/*">>},
 {<<"accept-encoding">>,<<"gzip">>},
 {<<"accept-language">>,<<"es-ES,es;q=0.9">>},
 {<<"cdn-loop">>,<<"cloudflare; subreqs=1">>},
 {<<"cf-ew-via">>,<<"15">>},
 {<<"cf-ipcontinent">>,<<"EU">>},
 {<<"cf-ipcountry">>,<<"ES">>},
 {<<"cf-iplatitude">>,<<"41.39490">>},
 {<<"cf-iplongitude">>,<<"2.17560">>},
 {<<"cf-ray">>,<<"86f90fae53e85e5c-MAD">>},
 {<<"cf-region">>,<<"Catalonia">>},
 {<<"cf-region-code">>,<<"CT">>},
 {<<"cf-timezone">>,<<"Europe/Madrid">>},
 {<<"cf-visitor">>,<<"{\"scheme\":\"https\"}">>},
 {<<"cf-worker">>,<<"hdsplus.workers.dev">>},
 {<<"content-length">>,<<"74">>},
 {<<"content-type">>,<<"text/plain">>},
 {<<"host">>,<<"stats.hdsplus.co">>},
 {<<"origin">>,<<"https://hdsplus.co">>},
 {<<"priority">>,<<"u=3, i">>},
 {<<"referer">>,<<"https://hdsplus.co/">>},
 {<<"sec-fetch-dest">>,<<"empty">>},
 {<<"sec-fetch-mode">>,<<"cors">>},
 {<<"sec-fetch-site">>,<<"cross-site">>},
 {<<"user-agent">>,
  <<"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15">>},
 {<<"x-forwarded-for">>,<<"2a06:98c0:3600::103, 188.114.111.178">>},
 {<<"x-forwarded-proto">>,<<"https">>},
 {<<"x-forwarded-scheme">>,<<"https">>},
 {<<"x-real-ip">>,<<"188.114.111.178">>}], request_path=><<"/api/event">>, resp_body=>nil, resp_cookies=>#{}, resp_headers=>[{<<"cache-control">>,<<"max-age=0, private, must-revalidate">>},
 {<<"x-request-id">>,<<"F8NdhKd16y-Y36EAAPiC">>},
 {<<"access-control-allow-credentials">>,<<"true">>},
 {<<"access-control-allow-origin">>,<<"*">>},
 {<<"access-control-expose-headers">>,<<>>}]})
ruslandoga commented 7 months ago

Do you know where x-forwarded-for and x-real-ip come from? One of them seems to be wrong. According to https://developers.cloudflare.com/fundamentals/reference/http-request-headers/#x-forwarded-for CloudFlare adds the client IP address (the real IP address) to the beginning of the list. And since Plausible is reading it from the beginning of the list, it's not a bug in Plausible.