Opened 6 years ago

Closed 6 years ago

#664 closed defect (invalid)

$upstream_http_var not able to be used in proxy_set_header

Reported by: Joel Gilliland Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.6.x
Keywords: Cc:
uname -a: Linux 2.6.32-279.el6.x86_64
nginx -V: nginx version: nginx/1.6.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)

also tried yum installed nginx.x86_64 1.6.2-1.el6.ngx as well as 1.0.15-10.el6

Description

Maybe I'm doing this wrong, but see below.

Doesn't work:

upstream myapp {

server myapplication:8080;

}

upstream php {

server 127.0.0.1:9000;

}

server {

...

location ~ /protected/ {

internal;
rewrite /protected(.*) /myapp$1 break; #this is to rewrite the original path back to the original value to pass to myapp. This prevent CSRF errors. Removing this has no effect on outcome.
proxy_set_header MYVAR $upstream_http_myvar;
proxy_pass http://myapp;

}


location ~ /myapp {

fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME $document_root/my-x-accel-script.php;
include fastcgi_params;

}


...

}

Works:

upstream myapp {

server myapplication:8080;

}

upstream php {

server 127.0.0.1:9000;

}

server {

...

location ~ /protected/ {

internal;
if ($upstream_http_myvar != "") {

set $myvar $upstream_http_myvar;

}
rewrite /protected(.*) /myapp$1 break;
proxy_set_header MYVAR $myvar;
proxy_pass http://myapp;

}


location ~ /myapp {

fastcgi_pass php;
fastcgi_param SCRIPT_FILENAME $document_root/my-x-accel-script.php;
include fastcgi_params;

}


...

}

Change History (1)

comment:1 by Maxim Dounin, 6 years ago

Resolution: invalid
Status: newclosed

This behaviour is correct. The $upstream_http_* variables are response headers from the current request to the upstream server, and during proxy_set_header evaluation they are expected to have empty values - as a response to the current request isn't yet received. If you want to use headers returned by a previous response (e.g., after X-Accel-Redirect) - you have to use set to save previous values somewhere.

Note: See TracTickets for help on using tickets.