Connection timeout with NGINX

I’m trying to run YOURLS via an NGINX server.

I’ve got it to a state where it’s working okay for /admin and /<any short link which exists>, but for / or /<non-existent short URL> I get an error 522, connection timeout.

Here’s my NGINX config (with some redactions). Does anyone know what might be wrong?

server {
	listen 80;
	listen [::]:80;
	listen 443 ssl;
	listen [::]:443 ssl;

	server_name doma.in;
	
	root /var/www/doma.in;

	index index.php;	

	ssl_certificate doma.in;
	ssl_certificate_key doma.in;

	# Rewrites
	location ~ /user.*$ {
		deny all;
	}

	location = / {
   		return 301 http://elsewhere;
  	}

	location / {
   		try_files $uri $uri/ /yourls-loader.php$is_args$args;
  	}

  	# PHP engine
	location ~ \.php$ {
		fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
		fastcgi_index index.php;
		include fastcgi_params;
 	 }
}

https://github.com/YOURLS/YOURLS/wiki/Nginx-configuration ?

Not a nginx user myself.

That’s where I’ve copied the above config from. The only additions are the location = / and location ~ /user.*$ blocks, but I have the same result removing them.

The location = / should redirect the root to another site but does nothing.

The location ~ /user.*$ block successfully returns a 403 Forbidden on /user and /user/config.php etc.