programing

nginx-업스트림 서버에서 사용자 정의 헤더 읽기

nasanasas 2020. 11. 24. 08:04
반응형

nginx-업스트림 서버에서 사용자 정의 헤더 읽기


nginx를 역방향 프록시로 사용하고 있으며 성공하지 않고 업스트림 서버 (Apache)의 응답에서 사용자 지정 헤더를 읽으려고합니다. Apache 응답은 다음과 같습니다.

HTTP/1.0 200 OK
Date: Fri, 14 Sep 2012 20:18:29 GMT 
Server: Apache/2.2.17 (Ubuntu)
X-Powered-By: PHP/5.3.5-1ubuntu7.10
Connection: close
Content-Type: application/json; charset=UTF-8
My-custom-header: 1

My-custom-header 에서 값을 읽고 if 절에서 사용 하고 싶습니다 .

location / {
    // ...
    // get My-custom-header value here
    // ...
}

이것이 가능한가? 미리 감사드립니다.


$ http _ name_of_the_header_key

origin = domain.com, 헤더에 있는 경우 $http_origin" domain.com " 을 가져 오는 데 사용할 수 있습니다.

nginx에서는 임의의 요청 헤더 필드를 지원합니다. 위의 예에서 변수 이름의 마지막 부분은 대시가 밑줄로 대체 된 소문자로 변환 된 필드 이름입니다.

참조 문서 : http://nginx.org/en/docs/http/ngx_http_core_module.html#var_http_

귀하의 예를 들어 변수는 $http_my_custom_header.


나는 같은 문제에 직면했다. 나는 모두를 시도 $http_my_custom_header하고 $sent_http_my_custom_header있지만 나를 위해 작동하지 않았다.

이 문제는 $upstream_http_my_custom_header.


$ http_MY_CUSTOM_HEADER 사용

다음과 같이 쓸 수 있습니다.

set my_header $http_MY_CUSTOM_HEADER;
if($my_header != 'some-value') {
#do some thing;
}

참고 URL : https://stackoverflow.com/questions/12431496/nginx-read-custom-header-from-upstream-server

반응형