Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to forward http 2 protocol version via proxy?

I have a simple rails application

(browser) -> (nginx latest; proxy_pass) -> rails (latest)

How do I configure nginx to notify rails that nginx received an HTTP/2 request via a different header IE: my_"http_version = 2.0"? proxy_pass communicates with rails via HTTP 1.1 and I want to know if the original request was http/2.

Thank you!

like image 743
Daniel Avatar asked Jan 07 '23 19:01

Daniel


1 Answers

This is similar to what the X-Forwarded-For and X-Forwarded-Proto headers are used for, but there not a standard header used to communicate the HTTP protocol version to the backend. I recommend using this:

proxy_set_header X-Forwarded-Proto-Version $http2;

The $http2 variables comes from ngx_http_v2_module which I presume you are using with Nginx to server HTTP/2.

The difference between $http2 and $server_protocol is that $http2 works more like a boolean, appearing blank if the HTTP/1 protocol was used. $server_protocol will contain values like "HTTP/1.1" or "HTTP/2.0", so it could also be a good choice depending on your needs.

like image 88
Mark Stosberg Avatar answered Jan 10 '23 18:01

Mark Stosberg