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

Maxim Dounin mdounin at mdounin.ru
Mon Jun 8 20:58:10 UTC 2020


Hello!

On Mon, Jun 08, 2020 at 08:57:56PM +0100, Alan Chandler wrote:

> 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.

[...]

> 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?

Trailers are only supported in gRPC proxying (grpc_pass), where 
they are required for gRPC.  Trailers are not supported by 
proxy_pass.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list