Implementing HTTP/2 Reverse Proxy with Nginx
Hello, it's me, the incompetent one.
My recent articles seem to be struggling with HTTP/2 support...
$ curl https://soulminingrig.com/
curl: (92) Invalid HTTP header field was received: frame type: 1, stream: 1, name: [upgrade], value: [h2,h2c]
So...
Upgrade can only be used for http.
Since the connection between Nginx and Apache is HTTP1.1, this header information is included, causing curl to complain when communicating via HTTP/2, which is the HTTPS standard.
So I thought, 'What if I just remove this?' and tried it, and it worked.
Roughly speaking, I was delivering it with header information from HTTP communication, so if I adapt it to HTTP/2, it should work, right? That's the gist of it.
For Japanese information, I think NIC's article is the easiest to understand.
Nginx Configuration
It seems that all you need to do is set this in the location directive and remove the Upgrade header.
It might not be necessary, but since it's HTTP communication, I made it explicit.
proxy_hide_header Upgrade;
proxy_http_version 1.1;
Time to curl!
If you do curl -I with this...
$ curl -I https://soulminingrig.com/
HTTP/2 200
server: nginx/1.27.0
date: Thu, 21 Nov 2024 22:44:47 GMT
content-type: text/html
content-length: 15375
vary: Accept-Encoding
last-modified: Thu, 21 Nov 2024 03:45:14 GMT
etag: "3c0f-627641819d3e9"
accept-ranges: bytes
vary: Accept-Encoding
content-security-policy: upgrade-insecure-requests
alt-svc: h3=":443"; ma=86400
x-content-type-options: nosniff
It worked!!!
I have my farewell party today, so I can drink alcohol without any worries!
See you next time. Best regards.