小编Tal*_*sin的帖子

谷歌分析 4 使用 nginx 进行反向代理

我有一个主要工作的 nginx 反向代理来处理与 ga4 的接口。我遇到的问题是,我网站的访问者的地理位置数据全部来自弗吉尼亚州阿什本(我的白种人居住的地方)。

这是我的 nginx 配置,其中编辑了特定于站点的数据:

events {
    worker_connections 4096;
}

http {
    set_real_ip_from 10.1.20.0/24;
    set_real_ip_from 10.1.30.0/24;
    real_ip_header X-Forwarded-For;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referrer" '
                    '"$http_user_agent" "$http_x_forwarded_for" ';

    access_log /var/log/nginx/access.log main;
    error_log /var/log/nginx/error.log notice;
    rewrite_log on;

    server {
        listen 80;
        server_name _;
        client_max_body_size 500M;
        location / {
            include uwsgi_params;
            uwsgi_pass 0.0.0.0:8000;
        }

        location /workaround-ga4/ {
            resolver 8.8.8.8;
            proxy_set_header X-real-ip $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            rewrite /workaround-ga4/([^/]+) /g/collect?$args&uip=$remote_addr break;
            proxy_pass https://www.google-analytics.com;
        } …
Run Code Online (Sandbox Code Playgroud)

google-analytics nginx nginx-reverse-proxy google-analytics-4

2
推荐指数
1
解决办法
1766
查看次数