title: How to remove a response header in nginx after having stored its value in case of proxy_pass
body: <p>Fundamentally, I am having troubles to find out a way to remove a response header in nginx in case of proxy_pass after having stored it in a variable.
  proxy_hide_header doesn't let me store the value.</p>
  
  <p>In other words:</p>
  
  <p>I am trying to get access to a custom response header, save it into a variable, and get rid of it so that it will not be propagated to the client. That variable is then used in the access logs. 
  Unfortunately, the following doesn't seem to work: </p>
  
  <pre><code>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 ""; 
    }   
   }
  }
  </code></pre>
  
  <p>I am getting empty values for $sent_http_x_destination. </p>
  
  <p>Here is the curl request and response: </p>
  
  <pre><code># curl -Ov http://142.133.151.129:8090/ao3/vod/soccer/worldcup2014/final1
  
  &lt; HTTP/1.1 206 Partial Content
  &lt; Server: openresty/1.9.3.1
  &lt; Date: Tue, 16 Feb 2016 22:25:32 GMT
  &lt; Content-Type: application/octet-stream
  &lt; Content-Length: 99990100
  &lt; Connection: keep-alive
  &lt; X-Destination: 142.133.151.94 
  </code></pre>
  
  <p>Does anyone know how to remove "X-Destination" after having it stored and used for access log? I am getting "$destination_addr" with empty value.</p>
  
  <p>Thanks</p>