헤더 이름은 X-Google, X-Goog-, X-GFE 또는 X-Amz-로 시작되지 않아야 합니다.
다음 홉별 헤더에서는 Keep-Alive, Transfer-Encoding, TE, Connection, Trailer, Upgrade를 사용하면 안 됩니다. RFC 2616에 따라 이러한 헤더는 캐시로 저장되지 않거나 대상 프록시로 전파되지 않습니다.
헤더 이름은 Host 또는 authority가 아니어야 합니다. Host와 authority 모두 Google Cloud에 예약된 특수 키워드입니다. Envoy 기반 부하 분산기의 헤더를 수정할 수 없습니다.
대신 예약된 헤더 이름을 방해하지 않도록 다른 커스텀 헤더(예: MyHost)를 만드는 것이 좋습니다.
헤더 이름은 헤더 목록에 두 번 이상 나타나지 않아야 합니다.
헤더 이름은 대소문자를 구분하지 않습니다. 헤더 이름이 HTTP/2 백엔드로 전달되면 HTTP/2 프로토콜은 헤더 이름을 소문자로 인코딩합니다.
헤더 값에는 다음 속성이 있어야 합니다.
헤더 값은 올바른 HTTP 헤더 필드 정의여야 합니다(RFC 7230에 따라, 사용되지 않는 양식은 허용되지 않음).
헤더 값을 비워 둘 수 없습니다. 빈 헤더는 거부됩니다.
헤더 값에는 부하 분산기가 제공하는 값으로 확장되는 중괄호로 묶인 하나 이상의 변수가 포함될 수 있습니다. 헤더 값에 허용되는 전체 변수 목록은 헤더 값에 표시될 수 있는 변수를 참조하세요.
헤더 값에서 선행 공백과 후행 공백은 유의하지 않으며 백엔드로 전달되지 않습니다. 부하 분산기는 헤더 값에 중괄호를 허용하기 위해 두 개의 여는 중괄호({{)를 하나의 여는 중괄호({)로 해석하고, 두 개의 닫는 중괄호(}})를 하나의 닫는 중괄호(})로 해석합니다.
요청 또는 응답 헤더 추가
요청 또는 응답 헤더를 추가하려면 gcloud CLI를 사용하여 다음과 같이 URL 맵을 수정합니다.
커스텀 변수가 포함된 요청 헤더가 빈 문자열로 확인되면 빈 문자열 자리표시자와 함께 유지됩니다.
커스텀 요청 헤더에 커스텀 변수가 포함되어 있고 수신되는 클라이언트 요청에도 동일한 헤더가 포함되어 있으면 클라이언트 요청 헤더 값이 부하 분산기의 커스텀 헤더에서 제공된 새 값으로 대체됩니다.
헤더 값에 나타날 수 있는 변수
커스텀 헤더 값에 다음 변수가 나타날 수 있습니다.
변수
설명
client_region
클라이언트의 IP 주소와 연관된 국가(또는 리전)입니다. US 또는 FR과 같은 유니코드 CLDR 리전 코드입니다. 대부분의 국가에서 이 코드는 ISO-3166-2 코드와 바로 대응합니다.
client_rtt_msec
부하 분산기와 HTTP(S) 클라이언트 간의 예상 왕복 전송 시간(밀리초)입니다. 이는 RFC 2988에 따라 부하 분산기 TCP 스택으로 측정된 평활 왕복 시간(SRTT) 파라미터입니다.
평활 RTT는 RTT 측정에서 발생할 수 있는 변이와 이상을 처리하는 알고리즘입니다.
client_ip_address
클라이언트의 IP 주소입니다. 클라이언트에서 프록시를 사용하지 않거나 X-Forwarded-For 헤더가 조작되지 않는 한 이는 일반적으로 X-Forwarded-For 헤더의 다음으로 가까운 주소인 클라이언트 IP 주소와 동일합니다.
client_port
클라이언트의 소스 포트입니다.
client_encrypted
클라이언트와 부하 분산기 간의 연결이 암호화된 경우에는(HTTPS, HTTP/2 또는 HTTP/3 사용) true, 그렇지 않으면 false입니다.
client_protocol
클라이언트와 부하 분산기 간의 통신에 사용되는 HTTP 프로토콜입니다. HTTP/1.0, HTTP/1.1, HTTP/2 또는 HTTP/3 중 하나입니다.
origin_request_header
교차 출처 리소스 공유(CORS) 사용 사례의 경우 요청에서 Origin 헤더 값을 반영합니다.
server_ip_address
클라이언트가 연결되는 부하 분산기의 IP 주소입니다. 부하 분산기 여러 개에서 공통 백엔드를 공유할 때 유용합니다. X-Forwarded-For 헤더의 마지막 IP 주소와 동일합니다.
server_port
클라이언트가 연결되는 대상 포트 번호입니다.
tls_sni_hostname
TLS 또는 QUIC 핸드셰이크 중에 클라이언트가 제공한 경우 서버 이름 표시(RFC 6066에 정의된 대로)입니다.
호스트 이름은 소문자로 변환되고 후행 점은 모두 삭제됩니다.
tls_version
SSL 핸드셰이크 중에 클라이언트와 부하 분산기 간에 협상된 TLS 버전입니다. 가능한 값에는 TLSv1, TLSv1.1, TLSv1.2, TLSv1.3이 포함됩니다. 클라이언트가 TLS 대신 QUIC를 사용하여 연결하면 값은 QUIC입니다.
tls_cipher_suite
TLS 핸드셰이크 중에 협상된 암호 모음입니다. 값은 IANA TLS Cipher Suite 레지스트리에서 정의한 네 자리 16진수입니다(예: TLS_RSA_WITH_AES_128_GCM_SHA256의 경우 009C). QUIC 및 암호화되지 않은 클라이언트 연결의 경우 이 값은 비어 있습니다.
부하 분산기는 값을 확인할 수 없을 때 변수를 빈 문자열로 확장합니다. 예를 들면 다음과 같습니다.
TLS를 사용하지 않는 경우의 TLS 매개변수
요청에 Origin 헤더가 포함되지 않은 경우의 {origin_request_header}
IP 주소의 위치를 알 수 없는 경우의 지리적 위치 변수
지리적 값은 클라이언트의 IP 주소를 기반으로 한 추정치입니다. 때때로 Google은 정확도를 개선하고 지리적, 정치적 변화를 반영하기 위해 이러한 값을 제공하는 데이터를 업데이트합니다. 원래 X-Forwarded-For 헤더에 유효한 위치 정보가 포함되어 있더라도 Google은 부하 분산기에서 수신한 패킷에 포함된 소스 IP 주소 정보를 사용하여 클라이언트 위치를 추정합니다.
상호 TLS 커스텀 헤더
부하 분산기의 TargetHttpsProxy에 상호 TLS(mTLS)가 구성된 경우 다음과 같은 추가적인 헤더 변수가 제공됩니다.
변수
설명
client_cert_present
TLS 핸드셰이크 중 클라이언트가 인증서를 제공한 경우 true이고 그렇지 않으면 false입니다.
client_cert_chain_verified
클라이언트 인증서 체인이 구성된 TrustStore에 대해 확인된 경우 true이고 그렇지 않으면 false입니다.
client_cert_error
오류 조건을 나타내는 사전 정의된 문자열입니다. 오류 문자열에 대한 자세한 내용은 mTLS 클라이언트 검증 모드를 참조하세요.
인증서가 유효성 검사를 통과한 설정된 mTLS 연결의 클라이언트 리프 인증서입니다. 인증서 인코딩은 RFC 9440을 준수합니다. 바이너리 DER 인증서가 Base64로 인코딩되며(줄바꿈, 공백, Base64 알파벳 이외의 기타 문자 없음) 양쪽에서 콜론으로 구분됩니다.
client_cert_leaf가 인코딩되지 않은 상태에서 16KB를 초과하면 문자열 client_cert_validated_leaf_exceeded_size_limit가 client_cert_error에 추가되고 client_cert_leaf가 빈 문자열로 설정됩니다.
client_cert_chain
리프 인증서를 포함하지 않은 클라이언트 인증서가 검증을 통과한 설정된 mTLS 연결의 클라이언트 인증서 체인에 대한 표준 TLS 순서의 쉼표로 구분된 인증서 목록입니다. 인증서 인코딩은 RFC 9440을 준수합니다.
Base64 인코딩 전의 client_cert_leaf 및 client_cert_chain을 합친 크기가 16KB를 초과하면 문자열 client_cert_validated_chain_exceeded_size_limit가 client_cert_error에 추가되고 client_cert_chain이 빈 문자열로 설정됩니다.
제한사항
다음과 같은 제한사항이 적용됩니다.
리전 외부 애플리케이션 부하 분산기에서 사용하는 백엔드 서비스에 커스텀 헤더를 구성할 수 없습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# Create custom headers in URL maps\n\nThis page describes how custom headers work in URL maps used by\nregional external Application Load Balancers.\n\nCustom request and response headers let you specify additional headers that\nthe load balancer can add to HTTP(S) requests and responses. Depending on the\ninformation that the load balancer detects, these headers can include the\nfollowing information:\n\n- Latency to the client\n- Parameters of the TLS connection\n\n- Geographic location of the client's IP address\n\n| **Important:** Global external Application Load Balancers support header transformations in the [URL\n| map](/load-balancing/docs/https/setting-up-global-traffic-mgmt#request-response-headers) as well as in the [backend\n| service](/load-balancing/docs/https/custom-headers-global). However, the regional external Application Load Balancers only support header transformations in URL maps.\n\nBefore you begin\n----------------\n\nIf necessary, update to the latest version of the Google Cloud CLI: \n\n```\ngcloud components update\n```\n\nHow custom headers work\n-----------------------\n\nCustom headers work as follows:\n\n- When the load balancer makes a request to the backend, the load\n balancer adds request headers.\n\n The load balancer adds custom request headers only to the client requests, not\n to the health check probes. If your backend requires a specific header for\n authorization that is missing from the health check packet, the health check\n might fail.\n- The load balancer sets response headers before returning a\n response to the client.\n\nTo enable custom headers for regional external Application Load Balancers,\nyou specify a list of header names and header values in the URL map\nconfiguration file.\n\n**Header names** must have the following properties:\n\n- The header name must be a valid HTTP header-field name definition per [RFC 7230](https://tools.ietf.org/html/rfc7230).\n- The header name must not be `X-User-IP`.\n- The header name must not begin with `X-Google`, `X-Goog-`, `X-GFE`, or `X-Amz-`.\n- The following hop-by-hop headers must not be used: `Keep-Alive`, `Transfer-Encoding`, `TE`, `Connection`, `Trailer`, and `Upgrade`. In accordance with [RFC 2616](https://datatracker.ietf.org/doc/html/rfc2616#page-92), these headers are not stored by caches or propagated by the target proxies.\n- The header name must not be `Host` or `authority`. Both `Host` and `authority` are special keywords reserved by Google Cloud. You can't modify these headers for Envoy-based load balancers. Instead, we recommend that you create other custom headers (for example, `MyHost`) so that you don't interfere with the reserved header names.\n- A header name must not appear more than once in the list of headers.\n\nHeader names are case-insensitive. When header names are passed to an HTTP/2\nbackend, the HTTP/2 protocol encodes header names as lowercase.\n\n**Header values** must have the following properties:\n\n- The header value must be a valid HTTP header field definition per [RFC 7230](https://tools.ietf.org/html/rfc7230), with obsolete forms disallowed.\n- The header value can't be blank. Blank headers are rejected.\n- The header value can include one or more variables, enclosed by curly braces, that expand to values that the load balancer provides. For a complete list of variables allowed in the header value, see [Variables that\n can appear in the header value](#variables).\n\nIn header values, leading whitespace and trailing whitespace are insignificant\nand are not passed to the backend. To allow for curly braces in header values,\nthe load balancer interprets two opening curly braces (`{{`) as\na single opening brace (`{`), and two closing curly braces (`}}`) as a single\nclosing brace (`}`).\n\nAdd request or response headers\n-------------------------------\n\nTo add request or response headers, use the gcloud CLI to edit\nthe URL map as follows:\n**Note:** If you are using the Google Cloud console to add the request and response headers in the URL map, you need to enter the host address in the **Hosts** field and the path matcher section of the following YAML in the **Path matcher** field. \n\n### Regional\n\n```\n gcloud compute url-maps edit URL_MAP_NAME \\\n --region=REGION\n \n```\n\nFollowing is a sample YAML file that shows you how to use variables in custom\nheaders: \n\n```yaml\n defaultService: regions/REGION/backendServices/BACKEND_SERVICE_1\n name: regional-lb-map\n region: region/REGION\n hostRules:\n - hosts:\n - '*'\n pathMatcher: matcher1\n pathMatchers:\n - defaultService: regions/REGION/backendServices/BACKEND_SERVICE_1\n name: matcher1\n routeRules:\n - matchRules:\n - prefixMatch: /PREFIX\n priority: PRIORITY # 0 is highest\n routeAction:\n weightedBackendServices:\n - backendService: regions/REGION/backendServices/BACKEND_SERVICE_1\n weight: 100\n headerAction:\n requestHeadersToAdd:\n - headerName: X-header-1-client-region\n headerValue: \"{client_region}\"\n - headerName: X-header-2-client-ip-port\n headerValue: \"{client_ip_address}, {client_port}\"\n replace: True\n requestHeadersToRemove:\n - header-3-name\n responseHeadersToAdd:\n - headerName: X-header-4-server-ip-port\n headerValue: \"{server_ip_address}, {server_port}\"\n replace: True\n responseHeadersToRemove:\n - header-5-name\n - header-6-name\n \n```\n\nNote the following behaviors:\n\n- If a response header with custom variables resolves to an empty string, it is removed.\n- If a request header with custom variables resolves to an empty string, it is retained with an empty string placeholder.\n- If a custom request header includes a custom variable, and an incoming client request also includes the same header, the client request header value will be replaced with the new value provided by the load balancer's custom header.\n\nVariables that can appear in the header value\n---------------------------------------------\n\nThe following variables can appear in custom header values.\n\nThe load balancer expands variables to empty strings when it can't determine\ntheir values. For example:\n\n- TLS parameters when TLS is not in use\n- The `{origin_request_header}` when the request does not include an `Origin`\n header\n\n- Geographic location variables when the IP address's location is unknown\n\nGeographic values are estimates based on the client's IP address. From time to\ntime, Google updates the data that provides these values in order to improve\naccuracy and to reflect geographic and political changes. Even if the original\n`X-Forwarded-For` header contains valid location information, Google estimates\nclient locations by using the source IP address information contained in packets\nreceived by the load balancer.\n\nMutual TLS custom headers\n-------------------------\n\nThe following additional header variables are available if mutual TLS (mTLS) is\nconfigured on the load balancer's TargetHttpsProxy.\n\nLimitations\n-----------\n\nThe following limitations apply:\n\n- You can't configure custom headers on backend services used by regional external Application Load Balancers.\n\n\u003c!-- --\u003e\n\n- The following custom header variables aren't supported with\n regional external Application Load Balancers:\n\n - `cdn_cache_id`\n - `cdn_cache_status`\n - `client_region_subdivision`\n - `client_city`\n - `client_city_lat_long`"]]