Incorrect SSL certificate showing for virtualhost.

I have a problem with LetsEncrypt SSL certificate. Virtualmin has setup the certificate and reports it installed OK but when visiting the site browsers warn that the certificate is wrong, they are seeing a certificate for the first virtual host not the correct one for the domain. You can see the example at it lists the certificate as

I could use some help solving this.

Joe on this thread resolved the problem

You’ve likely got one or more VirtualHost sections with *:443, while others have (where is your IP). That can cause weird behavior…Apache understands how it decides what to serve, but nobody else can.

I had the same problem and am posting here because this is the most recent thread to describe the problem. My resolution was different.

I have several IP’s on my virtualmin instance. What I found was that the site was bound to IP 1, while DNS was pointing people to IP 2. Once I updated the domain config within virtualmin to match what DNS was pointing to, the correct SSL certificate was served.

To clarify, this apparently never caused a problem over http, so this misconfiguration was missed for several months.