The certificate must cover the hostname visitors or applications actually use. For example, example.com and www.example.com are distinct hostnames unless the certificate includes both.
Before generating a CSR or buying a certificate, list the hostnames that need coverage. A certificate can include multiple names when the issuer and certificate type support Subject Alternative Names (SANs).
A valid certificate for the wrong hostname will still produce a hostname-mismatch warning.