Absolutely correct, it's surprisingly difficult to get a really good working configuration with no weird fallbacks or side effects and have working http2. I have five server blocks per domain name when using nginx, some are reusable though, here:
* Port 80 with wrong domain - close connection, nothing legit does this
* Port 80 with right (www. and .) domain - redirect to https://
* Port 443 with no SNI - close connection, nothing legit does this
* Port 443 with www. SNI (http2 enabled) - redirect
* Port 443 with . SNI (http2 enabled) - display proper page
Not surprisingly it tremendously cut down the amount of exploit scanners and bad bots from logs (they seem to rely on everyone not enforcing SNI) and managed to hide the server from Shodan :D. This is of course not to diss nginx, other servers e.g. caddy and apache were worse or even impossible to configure to the same point.
Hm? What about TLS is difficult with Caddy?
I wasn't aware that one could test for the existence of SNI in the server block.
server {
listen {replace_with_some_ip} ssl;
listen {replace_with_some_ipv6} ssl;
ssl_certificate /etc/ssl/snakeoil.pem;
ssl_certificate_key /etc/ssl/snakeoil.key;
server_name _ {replace_with_some_ip} {replace_with_some_ipv6};
return 444;
}
Should catch all TLS connections that have no SNI or try to connect straight with just IP and if snakeoil is generated right then it doesn't instantly reveal what's the real hostname.
One problem I've found is that if you have a redirect from HTTP to HTTPS, then you don't notice an extra redirect from HTTPS to HTTP (e.g. redirect from HTTPS plain domain to HTTP www, which then in the next request get upgraded from HTTP www to HTTPS www).
Combine that with the fact that it is surprisingly difficult to prevent the AWS load balancer from redirecting from HTTPS to HTTP. Literally Apache, Nginx, Tomcat, Jetty all get it wrong out of the box. I had to write this blog post to prevent myself from getting it wrong in the future: https://www.databasesandlife.com/jetty-redirect-keep-https/
The particular application I discovered that on did not accept HTTP traffic, so I discovered the extra redirect. Most people don't.