Thanks for the reply.
I've edited the first conf file to be:
<VirtualHost *:80>
ServerName myaccounts.live
DocumentRoot /var/www/html
#skip challenge requests and
<LocationMatch "^/(?!\.well-known)">
#send all other requests to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1
</LocationMatch>
</VirtualHost>
And ran the commands:
$ sudo systemctl stop apache2
$ sudo certbot certonly --webroot --dry-run --test-cert --renew-by-default --agree-tos -d myaccounts.live
But I've got this result:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for myaccounts.live
Input the webroot for myaccounts.live: (Enter 'c' to cancel): /var/www/html/
Waiting for verification...
Challenge failed for domain myaccounts.live
http-01 challenge for myaccounts.live
Cleaning up challenges
Some challenges have failed.
IMPORTANT NOTES:
- The following errors were reported by the server:
Domain: myaccounts.live
Type: connection
Detail: 162.250.127.130: Fetching
http://myaccounts.live/.well-known/acme-challenge/2BjHucgDr0gwqjJ_U_VjLV8_p613Ec6wZ1_V-zxdClo:
Connection refused
To fix these errors, please make sure that your domain name was
entered correctly and the DNS A/AAAA record(s) for that domain
contain(s) the right IP address. Additionally, please check that
your computer has a publicly routable IP address and that no
firewalls are preventing the server from communicating with the
client. If you're using the webroot plugin, you should also verify
that you are serving files from the webroot path you provided.
And you can see there is a folder for the webroot:
$ ls -al /var/www/html/
total 20
drwxr-xr-x 2 www-data www-data 4096 May 12 07:46 .
drwxr-xr-x 3 root root 4096 May 1 22:04 ..
-rw-r--r-- 1 www-data www-data 10918 May 1 22:04 index.html