[null,null,["最后更新时间 (UTC):2024-04-17。"],[[["\u003cp\u003eThis guide explains how to route all server-side Google Tag Manager traffic through a proxy server for enhanced security and control.\u003c/p\u003e\n"],["\u003cp\u003eBefore starting, ensure you have a Cloud Run or manually deployed server container (App Engine is not supported), a proxy server supporting \u003ccode\u003eHTTP CONNECT\u003c/code\u003e requests, and the ability to allowlist outbound traffic.\u003c/p\u003e\n"],["\u003cp\u003eTo set up proxy routing, define an \u003ccode\u003eHTTP_PROXY\u003c/code\u003e environment variable with your proxy server's URI for your server container.\u003c/p\u003e\n"],["\u003cp\u003eVerification involves checking Google Tag Manager's debug mode and your proxy server logs for successful requests to Google Tag Manager and other relevant endpoints.\u003c/p\u003e\n"],["\u003cp\u003eOptionally, you can allowlist specific outbound traffic, use BASIC authentication with your proxy, or disable the proxy for certain hosts using the \u003ccode\u003eNO_PROXY\u003c/code\u003e environment variable.\u003c/p\u003e\n"]]],["To route server-side tagging traffic through a proxy, ensure you have a deployed server container and a proxy server supporting HTTP CONNECT. Configure the `HTTP_PROXY` environment variable with the proxy server URI in your Cloud Run or manual deployment settings. Verify by checking Google Tag Manager's \"Requests\" tab and your proxy server logs. Optionally, allowlist specific domains and use BASIC authentication by adding credentials to the `HTTP_PROXY` value. Use `NO_PROXY` to specify hosts to bypass the proxy.\n"],null,["# Set up proxy server routing\n\n\u003e This document is for developers who want to route all server-side tagging\n\u003e traffic through a proxy server.\n\nBefore you begin\n----------------\n\nBefore you can set up proxy server routing, make sure you have:\n\n- A server container deployed on [Cloud Run](https://developers.google.com/tag-platform/tag-manager/server-side/cloud-run-setup-guide) or via\n [manual setup](https://developers.google.com/tag-platform/tag-manager/server-side/manual-setup-guide).\n\n | **Note:** App Engine deployments don't support proxying traffic.\n- A [proxy server](https://developer.mozilla.org/en-US/docs/Web/HTTP/Proxy_servers_and_tunneling) deployed that supports\n [`HTTP CONNECT`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT) requests.\n\n- The ability to allowlist specific outbound traffic from the proxy server,\n for example, using [VPC](https://cloud.google.com/vpc),\n [Firewall](https://cloud.google.com/firewall), or Proxy access control lists\n (ACLs).\n\nConfigure proxy server routing\n------------------------------\n\n### Cloud Run\n\nTo forward traffic to a proxy for Cloud Run deployments:\n\n1. [Open Cloud Run](https://console.cloud.google.com/run)\n2. Choose your server-side tagging Cloud Run instance.\n3. Click **EDIT \\& DEPLOY NEW REVISION**. The deploy revision screen opens.\n4. Under **Container(s)**, choose your server container. A new screen with the container setting opens.\n5. To expand the service configuration, select the **Variables \\& Secrets**\n tab. Click the **Add Variable** button and add the following environment\n variable:\n\n 1. **Name** : `HTTP_PROXY`\n 2. **Value** : URI of the proxy server (e.g. `https://proxy.example.com:3333` or `http://32.12.83.10`)\n\n | **Note:** The protocol must be either HTTP or HTTPS\n6. Click **Done**.\n\n7. Confirm your revisions and click **Deploy**.\n\n### Manual deployment\n\nTo forward traffic to a proxy for manual deployments:\n\n1. Define an environment variable accessible to the Docker image:\n\n 1. **Name** : `HTTP_PROXY`\n 2. **Value** : URI of the proxy server (e.g. `https://proxy.example.com` or `http://32.12.83.10:1234`)\n\n | **Note:** The protocol must be either HTTP or HTTPS\n2. Run your Docker image with the new environment variable.\n\n docker run -p 8080:8080 \\\n -e CONTAINER_CONFIG=\u003cvar label=\"container_config\" translate=\"no\"\u003eCONTAINER_CONFIG\u003c/var\u003e \\\n -e HTTP_PROXY=\u003cvar label=\"proxy_url\" translate=\"no\"\u003ePROXY_URL\u003c/var\u003e \\\n gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable\n\n**Result:** Your server-side tagging deployment sends all outbound traffic to\nthe proxy endpoint you specified in the environment variable.\n\nVerify the proxy server setup\n-----------------------------\n\nTo verify your proxy requests setup, check both Google Tag Manager and your\nproxy server configuration.\n\nTo verify your server container proxies requests:\n\n1. [Open Google Tag Manager](https://tagmanager.google.com/#/home)\n\n2. Open your server container.\n\n3. Open [Preview](https://developers.google.com/tag-platform/tag-manager/server-side/debug) mode. In the **Requests** tab:\n\n 1. Ensure your client claims the incoming request.\n 2. Ensure that your tags and variables successfully send outgoing HTTP requests.\n 3. To check whether a request was sent through a proxy server, click a HTTP request to view the **HTTP Request Details**.\n\nTo verify your proxy setup:\n\n1. Check your network and proxy server logs. At a minimum you should see successful requests to the following endpoints:\n - \u003chttps://www.googletagmanager.com\u003e\n - \u003chttps://tagmanager.google.com\u003e\n2. Check if there are requests to other endpoints.\n3. Depending on the server-side tagging features you use, you may also see requests made to other endpoints, such as [www.google-analytics.com](/tag-platform/tag-manager/server-side/www.google-analytics.com), [bigquery.googleapis.com](/tag-platform/tag-manager/server-side/bigquery.googleapis.com), or third-party endpoints. Allow-list any other endpoints that are needed for your tagging setup.\n\nOptional: Allow-list outbound traffic from your proxy server\n------------------------------------------------------------\n\nIf you block outbound traffic from your network or from your proxy server, you\nmust allowlist Google Tag Manager domains for your tagging server instance to\nwork. How you allowlist outbound traffic depends on your network environment and\nproxy software. Before you begin allowlisting endpoints, make sure that you\nunderstand your network topology.\n\nThe following domains are used to fetch, preview, and [debug](https://developers.google.com/tag-platform/tag-manager/server-side/debug)\nyour Google Tag Manager container:\n\n- `https://www.googletagmanager.com`\n- `https://tagmanager.google.com`\n- `${Preview server URL}`\n\nIf you host your Preview server on a different network than your proxy server or\nhave restrictive network rules, allowlist outbound traffic from\nthe proxy to the Preview server. The Preview server URL is defined when you\n[deploy your server container](https://developers.google.com/tag-platform/tag-manager/server-side/cloud-run-setup-guide).\n\nOptional: Use BASIC Authentication with your proxy server\n---------------------------------------------------------\n\nIf your organization requires authentication, you can use BASIC authentication\nwith all server types.\n\nTo use BASIC authentication, include the credentials (username/password) as part\nof the proxy server URL in the following format: \n\n HTTP_PROXY=http(s)://\u003cvar label=\"user_name\" translate=\"no\"\u003eUSER_NAME\u003c/var\u003e:\u003cvar label=\"password\" translate=\"no\"\u003ePASSWORD\u003c/var\u003e@\u003cvar label=\"proxy_url\" translate=\"no\"\u003ePROXY_URL\u003c/var\u003e\n\nEach request to the proxy sets the username and password in the\n[Proxy-Authorization header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Proxy-Authorization) as Base64 values.\n| **Caution:** Follow your cloud provider's best practices when storing and providing the `HTTP_PROXY` environment variable with BASIC authentication to the tagging server.\n\nIf you use Cloud Run, store the proxy endpoint credentials\nin [Secret Manager](https://cloud.google.com/secret-manager). Secret Manager\ngives Cloud Run access to the secret at startup time and resolves the value.\nLearn how to [configure secrets in Cloud Run](https://cloud.google.com/run/docs/configuring/services/secrets).\n\nOptional: Disable the proxy for specific hosts\n----------------------------------------------\n\nThe `NO_PROXY` environment variable lets you define a comma delimited list\nof hostnames that can't be sent through the proxy server.\n\nFor example, given:\n`NO_PROXY=example.com,169.254.169.254,diagnostics.example2.com:3131`\n\nThe sGTM container doesn't proxy any of the following requests:\n\n- `http://example.com`, `https://sub.example.com`, `https://other.example.com:123`\n- `http://169.254.169.254`, `https://169.254.169.254`, `http://169.254.169.254:123`\n- `http://diagonstics.example2.com:3131`, `https://diagonstics.example2.com:3131`\n\n| **Tip:** If you integrate with Bigquery or Firestore and deploy your tagging server to Google Cloud, you may need to define an exception for Google's [metadata server](https://cloud.google.com/compute/docs/metadata/overview#limitations) with `NO_PROXY=169.254.169.254,metadata.google.internal`"]]