Opened 10 years ago
Closed 10 years ago
#665 closed defect (duplicate)
$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;
}
...
}