A server certificate's CN must be exactly the same as the server's domain name. I suppose, in your case the common name must be "localhost" (w/o quotes).
Important: for sure, as you might have read in other answers, never use CN="localhost" in production.