Report this

What is the reason for this report?

Having issues setting up MongoDB SSL/TLS

Posted on September 27, 2020
vbg

By vbg

I wanted to try and link my droplet IP to say Cloudflare, ex mongo.example.com and use port 80 or 2095 on Cloudflare. I want to use Cloudflare STRICT but while setting up the SSL cert and keys I ended up getting lost and overflowed with different instructions. I haven’t been able to find any guide or example. A simple guide or link to a guide or if this is even possible would be nice as I’ve spent way more time on this then I should and want it to be done.

I was able to connect using the IP but not through Cloudflare, even just as a DNS.

I have tried setting my BindIP to a domain, however, this just errors and won’t let mongo start.

Current net config

net:
  tls:
    mode: allowTLS
    certificateKeyFile: /etc/ssl/mongodb.pem
  port: 2095
  • I have removed bindIP and it is there in the actual config.


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Heya,

Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.

To start, you’ll need to follow these steps:

  1. Create a CNAME record in Cloudflare pointing mongo.example.com to your droplet’s IP address or domain name.
  2. Set the SSL mode to Full (strict) in Cloudflare’s SSL/TLS settings.
  3. Install an SSL certificate on your droplet to secure the connection between Cloudflare and your droplet.
  4. Configure MongoDB to use your SSL certificate and listen on the desired port.

If you haven’t already, please first install an SSL certificate on your droplet. You can use Let’s Encrypt to get a free SSL certificate. You can follow this guide for securing Nginx with Let’s Encrypt on Ubuntu 20.04 as a reference. Adjust the tutorial as needed for MongoDB and your operating system if it’s different.

Next, make sure MongoDB is configured to use your SSL certificate, listening on the desired port, and allowing connections from Cloudflare IPs. You can find the relevant Cloudflare IP ranges by visiting https://www.cloudflare.com/ips/.

Once everything is set up, you should be able to connect to your MongoDB instance through mongo.example.com using Cloudflare.

For more information on how to set up SSL with MongoDB, refer to the official MongoDB documentation and this DigitalOcean tutorial on configuring SSL/TLS encryption for MongoDB on Ubuntu 20.04.

Hope that this helps!

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.