Opened 3 years ago

Closed 3 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:
Sensitive: no
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'


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

1) Internally we override Host header to and proxy_pass

location ~* /blablabla/(.*) {

proxy_set_header HOST;
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

V)..V)..HEAD /asset_files/-/2014/01/31/telecasts.csv HTTP/1.0M
Connection: closeM
User-Agent: curl/7.24.0 (x86_64-redhat-linux-gnu) libcurl/7.24.0 NSS/ zlib/1.2.5 libidn/1.18 libssh2/1.2.2
Accept: */*M

HTTP/1.1 200 OKM
x-rid: 1ok5rjv
Etag: "165143ec0b37d43cf2c2b7f292647526"M
Date: Sat, 01 Feb 2014 00:07:47 GMT
Last-Modified: Fri, 31 Jan 2014 18:15:36 GMTM
Content-Type: application/json; charset=utf-8
Content-Length: 1212M
Cache-Control: max-age=1801
X-Accel-Redirect: /internal_redirect/
X-Response-Time: 69ms
Connection: closeM

3) X-Accel-Redirect should tell nginx to go fetch that url, but it seems like it uses original host ( instead the one we modified with proxy_pass

HEAD /internal_redirect/ HTTP/1.0M
X-Geo: USM
Connection: close
User-Agent: curl/7.24.0 (x86_64-redhat-linux-gnu) libcurl/7.24.0 NSS/ zlib/1.2.5 libidn/1.18 libssh2/1.2.2M
Accept: */*

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

Change History (2)

comment:1 Changed 3 years ago by gansbrest@…

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

comment:2 Changed 3 years ago by mdounin

  • Resolution set to invalid
  • Status changed from new to closed

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.