How to close client HTTP/2 connections?

filex nginx-forum at forum.nginx.org
Fri Nov 23 08:49:13 UTC 2018


Hello,

we use NGINX as http/2 and TLS offloader. Therefore it is responsible for
connection handling. (Most of the requests are proxy_pass'ed to upstream
servers. However, some few requests are served from local files.)

Now, I would like to close the client connection under certain
circumstances. That could be the presence of a certain upstream response
header or status code.

I have tried

  more_set_headers -s '502 503' 'Connection: close';

This works for HTTP/1 connections.

However, this Connection header seems to be forbidden in h2. Triggering the
header with curl (-v --http2) yields an error:

  http2 error: Invalid HTTP header field was received: frame type: 1,
stream: 1, name: [connection], value: [close]
   curl: (92) HTTP/2 stream 1 was not closed cleanly: PROTOCOL_ERROR (err
1)

Ok, the connection is closed :) But quite elegantly.

And I forgot to mention that I would like to serve an error message, like a
"sorry…" HTML. (Therefore I couldn't use the 444 status.)

How could I do this for h2: Serve a last page and then say GOWAY?

Best regards,
Felix

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,282096,282096#msg-282096



More information about the nginx mailing list