nginx - read custom header from upstream server

前端 未结 3 1662
名媛妹妹
名媛妹妹 2020-12-04 11:20

I am using nginx as a reverse proxy and trying to read a custom header from the response of an upstream server (Apache) without success. The Apache response is the following

相关标签:
3条回答
  • 2020-12-04 11:32

    I was facing the same issue. I tried both $http_my_custom_header and $sent_http_my_custom_header but it did not work for me.

    Although solved this issue by using $upstream_http_my_custom_header.

    0 讨论(0)
  • 2020-12-04 11:34

    $http_name_of_the_header_key

    i.e if you have origin = domain.com in header, you can use $http_origin to get "domain.com"

    In nginx does support arbitrary request header field. In the above example last part of a variable name is the field name converted to lower case with dashes replaced by underscores

    Reference doc here: http://nginx.org/en/docs/http/ngx_http_core_module.html#var_http_

    For your example the variable would be $http_my_custom_header.

    0 讨论(0)
  • 2020-12-04 11:50

    Use $http_MY_CUSTOM_HEADER

    You can write some-thing like

    set my_header $http_MY_CUSTOM_HEADER;
    if($my_header != 'some-value') {
    #do some thing;
    }
    
    0 讨论(0)
提交回复
热议问题