nginx does not respond correctly to HTTP/1.1
I'm having an issue where certain clients that first try to connect via HTTP/1.1 are not correctly getting forwarded to HTTPS
curl -v http://indentationerror.com/
* Trying 217.45.175.173:80...
* Connected to indentationerror.com (217.45.175.173) port 80 (#0)
> GET / HTTP/1.1
> Host: indentationerror.com
> User-Agent: curl/7.73.0
> Accept: */*
>
* Received HTTP/0.9 when not allowed
* Closing connection 0
curl: (1) Received HTTP/0.9 when not allowed
However, with the command:
curl -v http://indentationerror.com/ --http2-prior-knowledge
nginx returns a 301 redirect as intended over HTTP/2
My config is currently:
server {
server_name www.indentationerror.com;
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl on;
root "/http/indentationerror.com/www";
include /etc/nginx/genericHandlers/indentationerror.com;
}
server {
server_name indentationerror.com;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
ssl on;
root "/http/indentationerror.com/www";
include /etc/nginx/genericHandlers/indentationerror.com;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name $host;
return 301 https://$host$request_uri;
}
The broken part (added once I found the issue):
server {
server_name api.indentationerror.com;
listen 80 http2;
listen [::]:80 http2;
root "/http/indentationerror.com/api";
include /etc/nginx/genericHandlers/indentationerror.com;
}
server {
server_name api.indentationerror.com;
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl on;
root "/http/indentationerror.com/api";
include /etc/nginx/genericHandlers/indentationerror.com;
}
Solution 1:
I had an accidental "http2" directive on one of my port 80 server directives (you can see it in the "api" server). For some reason using this on one server block affects others. Thanks to Michael for the hint. For anyone else experiencing the issue, removing "http2" from all of your port 80 servers fixes the issue.