Why does nginx strip trailing headers from a proxied backend? How can I prevent it?

Alan Chandler alan at chandlerfamily.org.uk
Mon Jun 8 19:57:56 UTC 2020


I have nginx acting as the static file server for a single page web app 
I am developing. It acts as a proxy server for the "/api" portion on my 
url space.

The backend server is running on a different port on local host and is 
nodejs based.. I'm using nginx as an http2 front end and using http 1/1 
between nginx and the backend. In the main this is working well.

But I have one problem. I would like to make use of a trailing header. 
My outgoing request has the header "TE: trailers", and the response has 
a header "Trailers: API-Status" and then after the body it adds (using 
nodejs response.addTrailers({'API-Status': 'OK'})).

But nginx is stripping them out.

I can use curl to prove it

curl -b "MBFMVISIT=emailverify; expires=Sun, 07 Jun 2020 13:14:06 
GMT;path=/;" -H "Content-Type: application/json" -H "TE: trailers" -X 
GET -c cookie.jar -i https://footdev.chandlerfamily.org.uk/api/config/config

goes via nginx and outputs the response (including the initial 
'Trailers: API-Status' header, but not the trailing header

HTTP/2 200
server: nginx/1.18.0
date: Mon, 08 Jun 2020 19:39:41 GMT
content-type: application/json
trailer: API-Status
cache-control: no-cache

{"dcid":17,"pointsMap":"[1,2,4,6,8,12,16]","underdogMap":"[0,1,2,4,6,8]","playoffMap":"[1,2,4,6,8]","bonusMap":"[1,2,4,6,8,12,16]","defaultBonus":2,"clientLog":"ALL","clientLogUid":0,"version":"v4.0.0-alpha3","copyrightYear":2020,"cookieName":"MBBall","cookieVisitName":"MBFMVISIT","mainMenuIcon":"menu","status":true}


curl -b "MBFMVISIT=emailverify; expires=Sun, 07 Jun 2020 13:14:06 
GMT;path=/;" -H "Content-Type: application/json" -H "TE: trailers" -X 
GET -c cookie.jar -i http://localhost:2040/api/config/config

goes directly to the backend. in this curl outputs the initial headers, 
the response and then after the response the trailing header 
'API-Status: OK'

HTTP/1.1 200 OK
Trailer: API-Status
Content-Type: application/json
Cache-Control: no-cache
Date: Mon, 08 Jun 2020 19:40:14 GMT
Connection: keep-alive
Transfer-Encoding: chunked

{"dcid":17,"pointsMap":"[1,2,4,6,8,12,16]","underdogMap":"[0,1,2,4,6,8]","playoffMap":"[1,2,4,6,8]","bonusMap":"[1,2,4,6,8,12,16]","defaultBonus":2,"clientLog":"ALL","clientLogUid":0,"version":"v4.0.0-alpha3","copyrightYear":2020,"cookieName":"MBBall","cookieVisitName":"MBFMVISIT","mainMenuIcon":"menu","status":true}API-Status: 
OK

(The API-Status: OK is bolded by curl along with the pre reply headers)

My nginx config for the proxy is

location /api/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass http://localhost:2040;
proxy_redirect default;
proxy_buffering on;
proxy_cache off;
}

So how do I tell nginx to pass the trailing header?  I have buffering 
on, but doesn't seem to have changed anything - it didn't work when I 
had it off.



More information about the nginx mailing list