HTTP type for local reverse proxy

Hi,

I want to run a web server (on the same device) using nginx as reverse proxy.
I was wondering what HTTP type my app should use.

Should I accept both HTTP/1.1 and HTTP2 (e.g. to allow nginx to directly pass data)?
Should I only accept HTTP2 and configure nginx to convert HTTP/1.1 (e.g. because nginx parses requests anyways, and HTTP2 would allow using fewer sockets thanks to multiplexing)?
Maybe there is some kind of ‘secret’ transfer type I could use for more performance (e.g. using UDP since packet loss over socket to localhost is unlikely)?

Thanks in advance.

Hey @Ruttie! Let me start with your last comment since it’s the easies to answer:

Maybe there is some kind of ‘secret’ transfer type I could use for more performance (e.g. using UDP since packet loss over socket to localhost is unlikely)?

UDP is actually used by HTTP/3 with quic! When it works, it works quite well. However, it is still a very recent standard and the level of adoption varies amongst clients and browsers. NGINX released experimental support for HTTP/3 a couple years ago and you can enable it via the http v3 module. You can find the latest data re the various levels of HTTP/3 client/server implementations here https://interop.seemann.io.

Should I accept both HTTP/1.1 and HTTP2 (e.g. to allow nginx to directly pass data)?
Should I only accept HTTP2 and configure nginx to convert HTTP/1.1 (e.g. because nginx parses requests anyways, and HTTP2 would allow using fewer sockets thanks to multiplexing)?

This is a slightly more tricky question to answer. There are both potential performance improvements and drawbacks when using HTTP/2 over HTTP/1.1. This is one of those cases where the answer truly is “it depends on your use case”. I would suggest reading through this O’Reilly article (or any number of other articles you can find online) and determining what version (or even whether both versions) of HTTP better fits your use case.

Long term, HTTP/3 is likely going to become the defacto standard, but we are at best still a few years away from reaching full scale mass adoption.

It seems you might’ve misunderstood my question (or I just phrased it wrongly).
I’m not asking what my site should use, more what my site should use to talk to nginx.
I might be misunderstanding how nginx works, but I thought that nginx parses all http requests, then picks the place to send them, then reencodes them for that place.
The docs state that HTTP/1 is used by default (which does seem a little weird because I believe every backend should support at least 1.1).

It does indeed seem like I somewhat misunderstood the question! The info I shared is still useful when determining which version of HTTP to use for incoming requests to NGINX itself, so hopefully it’s still useful to other folks :smiley:

In so far as the proxied HTTP version, the default is HTTP/1 due to historical legacy reasons. NGINX defaults very rarely change over time, and given NGINX has been around for a very long time, HTTP/1 was the default/only real certified version available then the directive was introduced in NGINX 1.1.4.

Like you said though, where possible, it makes sense to use HTTP/1.1 since by this day it’s the defacto standard. There is no support for HTTP/2 due to a few reasons detailed in this mailing list thread. Using proxy_http_version 3.0 is currently not available even though it is a work in progress.

All of the above is a very roundabout way to say that as of right now, the best answer for your question is likely going to be HTTP 1.1 until support for HTTP 3.0 goes live.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.