小编dev*_*per的帖子

在proxy_pass情况下如何存储响应值后如何在nginx中删除响应头

从根本上讲,在将proxy_pass存储在变量中之后,我很难找到一种方法来删除nginx中的响应头(如果proxy_pass)。proxy_hide_header不允许我存储值。

换一种说法:

我试图访问自定义响应标头,将其保存到变量中,并摆脱它,以便它不会传播到客户端。然后在访问日志中使用该变量。不幸的是,以下内容似乎无效:

http {

log_format main '$remote_addr $http_host $destination_addr [$time_local]   
"$request" $status';
access_log /opt/logs/access.log main;

server { 
 listen 142.133.151.129:8090 default; 

 ##This is my internal variable for the response header field 
 set $destination_addr "-"; 

 location / { 
   proxy_pass http://my_upstream_server; 

   #store the response header field
   set $destination_addr $sent_http_x_destination; 

   #now get rid of this response header field
   set $sent_http_x_destination ""; 
  }   
 }
}
Run Code Online (Sandbox Code Playgroud)

我正在获得$ sent_http_x_destination的空值。

这是curl请求和响应:

# curl -Ov http://142.133.151.129:8090/ao3/vod/soccer/worldcup2014/final1

< HTTP/1.1 206 Partial Content
< Server: openresty/1.9.3.1
< Date: Tue, 16 …
Run Code Online (Sandbox Code Playgroud)

nginx

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

nginx ×1