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.. Im 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
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'
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 off;
proxy_cache off;
}
So how do I tell nginx to pass the trailing header?
The backend server is running on a different port on local host and is nodejs based.. Im 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
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'
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 off;
proxy_cache off;
}
So how do I tell nginx to pass the trailing header?