﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc	uname	nginx_version
497	X-Accel-Redirect problem with proxy_pass and proxy_set_heder	gansbrest		"Will try to describe the problem we have:

We are doing proxy_pass to another domain and change host header (as you can see below), backend returns X-Accel-Redirect with the location of the file to serve, but for some reason on step 3 belowб when nginx receives X-Accel-Redirectб it's using original Host, not the one we changed with proxy_set_header.. which means it's captured by wrong server section and 404 as a result..

------------------------------

curl -I http://beta.fastcodesign.com/blablabla/asset_files/-/2014/01/31/telecasts.csv

1) Internally we override Host header to beta.assets.fastcodesign.com and proxy_pass

location ~* ^/blablabla/(.*) { 
  proxy_set_header HOST beta.assets.fastcompany.com;
  proxy_pass http://txjp/$1$is_args$args;
} 

upstream txjp {
  server localhost:8880;
}

2) Using tcpdump on port 8880 we can see that request goes to backend with new header beta.assets.fastcompany.com

V)..V)..HEAD /asset_files/-/2014/01/31/telecasts.csv HTTP/1.0^M
HOST: beta.assets.fastcompany.com^M
Connection: close^M
User-Agent: curl/7.24.0 (x86_64-redhat-linux-gnu) libcurl/7.24.0 NSS/3.12.10.0 zlib/1.2.5 libidn/1.18 libssh2/1.2.2^M
Accept: */*^M

HTTP/1.1 200 OK^M
x-rid: 1ok5rjv^M
Etag: ""165143ec0b37d43cf2c2b7f292647526""^M
Date: Sat, 01 Feb 2014 00:07:47 GMT^M
Last-Modified: Fri, 31 Jan 2014 18:15:36 GMT^M
Content-Type: application/json; charset=utf-8^M
Content-Length: 1212^M
Cache-Control: max-age=1801^M
X-Accel-Redirect: /internal_redirect/assets.fastcompany.com.s3-website-us-east-1.amazonaws.com/asset_files/-/2014/01/31/telecasts.csv^M
X-Response-Time: 69ms^M
Connection: close^M


3) X-Accel-Redirect should tell nginx to go fetch that url, but it seems like it uses original host (beta.fastcodesign.com) instead the one we modified with proxy_pass

HEAD /internal_redirect/assets.fastcompany.com.s3-website-us-east-1.amazonaws.com/asset_files/-/2014/01/31/telecasts.csv HTTP/1.0^M
X-Real-IP: 23.23.118.249^M
X-Forwarded-For: 23.23.118.249^M
Host: beta.fastcodesign.com^M
X-Geo: US^M
Connection: close^M
User-Agent: curl/7.24.0 (x86_64-redhat-linux-gnu) libcurl/7.24.0 NSS/3.12.10.0 zlib/1.2.5 libidn/1.18 libssh2/1.2.2^M
Accept: */*^M

TTP/1.1 404 Not Found^M
x-rid: hwii1c^M
Content-Type: application/json; charset=utf-8^M
Content-Length: 2^M
X-Response-Time: 288ms^M
Date: Sat, 01 Feb 2014 00:07:47 GMT^M
Connection: close


"	defect	closed	major		nginx-core	1.4.x	invalid			"Linux beta-jetpack-01 3.2.22-35.60.amzn1.x86_64 #1 SMP Thu Jul 5 14:07:24 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
"	"nginx version: nginx/1.4.2
built by gcc 4.6.3 20120306 (Red Hat 4.6.3-2) (GCC) 
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx-1.4.2 --conf-path=/etc/nginx/nginx.conf --sbin-path=/opt/nginx-1.4.2/sbin/nginx --with-http_perl_module --with-debug --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module --with-http_realip_module --with-http_geoip_module --with-ld-opt='-Wl,-R,/usr/local/lib -L /usr/local/lib'"
