How to migrate from NGINX Ubuntu 20

Yep, it should.

Probably best if you try it locally or on a staging server first, if you’re concerned.

For your *.example.com server, are you using a wildcard certificate? If so, you’ll need to configure Caddy to use a DNS provider module. See here:

Your config would probably look something like this:

example.com {
	root /var/www/html
	encode gzip
	php_fastcgi unix//var/run/php/php7.2-fpm.sock
	file_server
}

*.example.com {
	tls {
		dns <provider> <config>
	}

	root * /var/www/html/{labels.2}
	encode gzip
	php_fastcgi unix//var/run/php/php7.2-fpm.sock
	file_server

	handle_errors {
		root * /var/www/html
		rewrite * /{http.error.status_code}.html
		file_server
	}
}