Opened 11 years ago

Closed 11 years ago

#497 closed defect (invalid)

X-Accel-Redirect problem with proxy_pass and proxy_set_heder

Reported by: gansbrest Owned by:
Priority: major Milestone:
Component: nginx-core Version: 1.4.x
Keywords: Cc:
uname -a: 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 -V: 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'

Description

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.0M
HOST: beta.assets.fastcompany.com
M
Connection: closeM
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 OKM
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 GMTM
Content-Type: application/json; charset=utf-8
M
Content-Length: 1212M
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.csvM
X-Response-Time: 69ms
M
Connection: closeM

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.0M
X-Real-IP: 23.23.118.249
M
X-Forwarded-For: 23.23.118.249M
Host: beta.fastcodesign.com
M
X-Geo: USM
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.2M
Accept: */*
M

TTP/1.1 404 Not FoundM
x-rid: hwii1c
M
Content-Type: application/json; charset=utf-8M
Content-Length: 2
M
X-Response-Time: 288msM
Date: Sat, 01 Feb 2014 00:07:47 GMT
M
Connection: close

Change History (2)

comment:1 by gansbrest, 11 years ago

We also tried to set full path on the backend for the X-Accel-Redirect header including Host ( ie X-Accel-Redirect http://domain.com/file ) but it returns same error, probably hostname in x-accel-redirect is not supported..

comment:2 by Maxim Dounin, 11 years ago

Resolution: invalid
Status: newclosed

The X-Accel-Redirect header is to do an internal redirect to the specified URI, see proxy_ignore_headers and internal. If you want nginx to proxy a redirected request to another domain, you have to write a location block to do this.

Note: See TracTickets for help on using tickets.