The http2 on; directive only appeared in 1.25.1. On the 1.24 that ships with Ubuntu 24.04 the old form is still required:
listen 443 ssl http2;
Using the new directive on 1.24 fails the config test with an unknown directive error, which is at least loud.