Search code examples
mongodbsslparse-server

MongoDB & Let's Encrypt = "server certificate does not match the host name"


for my master thesis i want to set up a parse-server to handle the backend. I'm an engineer not a programmer, so there are some issues i ran into. Most of them could be solved by searching the web but this on is a bit tricky. I'm from Germany an my Professor want me to put the data on a server located in Germany.

I got kind of a VPS Droplet running Ubuntu 18.04 LTS and a domain from my University and installed the following to this point:

  • nginx + Let's Encrypt
  • Node.js
  • MongoDB

I also installed parse-server-example repo and parse-dashboard which runs fine with HTTP.

Next step is to secure MongoDB so i followed the following tutorial and everything worked as expected till the point when i tried to connect to the db.

https://www.digitalocean.com/community/tutorials/how-to-migrate-a-parse-app-to-parse-server-on-ubuntu-14-04

When connecting to mongoDB i get this response:

connecting to: mongodb://127.0.0.1:27017/
2018-09-15T01:12:32.808+0200 W NETWORK  [js] The server certificate 
does not match the host name. Hostname: 127.0.0.1 does not match SAN(s): xxxxxx.de www.xxxxxx.de 
MongoDB server version: 4.0.2

Now i'm stuck. Reading the mongoDB docs was interesting but not really helpful in my case.

https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/#install-mongodb-community-edition

I found the command...

mongo --host 127.0.0.1:27017

... and tried the VPS IP and also my domain name heading to the Server IP but it does not worked.


Solution

  • Although the hosts flag trick is a nice hack in general there's now an easier way to do this specifically for this use case:

    you can use "--sslAllowInvalidCertificates" as a flag...

    Needless to say, if security is a concern, use this with due discretion.

    [src: https://docs.mongodb.com/manual/reference/configuration-options/#net.ssl.allowInvalidHostnames]