Name based virtual hosts cause NET::ERR_CERT_COMMON_NAME_INVALID

Solution 1:

Argument to the VirtualHost directive must match a defined NameVirtualHost directive.

You can't use domain.com in the VirtualHost directive if you don't have NameVirtualHost domain.com defined in config, which is something not commonly used, * or IP is generally used for NameVirtualHost.

Since this VirtualHost is not valid, it loads the first or default VirtualHost it exists on that IP for port 443, which is anotherdomain.com whose SSL you are being served.