You need to issue a certificate that includes
subjectAltName=DNS:localhost (or your domain)
Modern browsers ignore CN and look in
subjectAltName