首页 > 解决方案 > Could not connect to MongoDB on the provided host and port with SSL/TLS encryption

问题描述

I'm follow the tutorial of MongoDB and I want to encrypt network traffic with certificates self-signed SSL/TLS in local. Once done this (I used OpenSSL), I start mongod in my cmd with the follow syntax:

mongod --sslMode requireSSL --sslPEMKeyFile test-server1.pem --sslCAFile test-ca.pem

The files .pem are signed follow the tutorials https://docs.mongodb.com/manual/appendix/security/ so I suppose that it's fine.

The instance is initiated and shows the follow message:

waiting for connections on port 27017 ssl

I start now the mongo shell with:

mongo --ssl --host localhost --sslPEMKeyFile test-client.pem --sslCAFile test-ca.pem

Then, this is the problem. The mongo shell terminal shows

....
Error: couldn't connect to server localhost:27017, connection attempt failed: HostUnreachable: Connection closed by peer
...

And the instance shows

....
2019-06-12T11:52:39.819+0200 I NETWORK [initandlisten] waiting for connections on port 27017 ssl
2019-06-12T11:54:25.642+0200 I NETWORK [listener] connection accepted from 127.0.0.1:51005 #1 (1 connection now open)
2019-06-12T11:54:26.560+0200 I NETWORK [conn1] end connection 127.0.0.1:51005 (0 connections now open)
....

The connection is open and immediately close. I have tried all. I think that the problem could be the files .cnf that are used for signed the certificates, but I dont know.

Thanks for help

标签: mongodbsslencryptionssl-certificate

解决方案


推荐阅读