Hi community,
I have created a droplet Ubuntu 20.04 (LTS) x64. Inside this server I have configured a MongoDB database (version 4.4), a NodeJS (version 14.18.3) and inside my NodeJS enviroment I have installed a frontend application (React) and a backend (Express).
I have the following status:
The issue: When I try to access MongodB through the backend “http://(iphost}:3333/login”, the backend stops working (Error: socket hang up) meaning that I might have an issue between the backend and MongodB. In more details it shows an error related to decryption (Error: Error during decryption (probably incorrect key). Original error: Error: error:04099079:rsa routines:RSA_padding_check_PKCS1_OAEP_mgf1:oaep decoding error), however my “.pem” file is correct and the address of this file is also correct.
My question: Is there any kind of limitation in terms of PORTS access that might avoid this communication between Backend (3333) and MongodB (27017)? Has anyone faced this kind of error? Any suggestion?
Important: This application (frontend+backend+mongodB) has the same configuration as I have installed and is working in my local computer.
Important(2): Unfortunatelly I cannot upgrade my system (mongodb, NodeJs and NPM) because it is a legacy application.
Many thanks and Regards
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.
Hey Marcos,
Happy to hear that you’ve made such a good progress. Here are a few steps that you can follow to help you with further troubleshooting this:
Review Firewall Settings: Start by reviewing your firewall settings. Ensure that your firewall isn’t blocking MongoDB’s default port (27017). You can check the active firewall rules using:
If necessary, allow traffic on MongoDB’s port:
Confirm MongoDB Configuration: If your MongoDB instance is running on your Droplet as well, verify MongoDB’s
mongod.conf
file to ensure it’s correctly set up to listen on the appropriate network interface. The configuration file is typically located at/etc/mongod.conf
. You should see a line likebindIp: 127.0.0.1
(for localhost connections) orbindIp: 0.0.0.0
(to listen on all interfaces).Testing MongoDB Connection: Test the MongoDB connection independently from your backend. Use the
mongosh
command:This helps confirm that MongoDB is running and accessible.
Backend Service Debugging: Start your Node.js backend and watch for errors. If it crashes after trying to connect to MongoDB, the console should provide some insight. You can start your Node.js app with:
Replace
app.js
with your main server file.Review Node.js MongoDB Connection String: In your Node.js application, ensure the MongoDB connection string is correctly formatted. It generally looks like this:
Inspect SSL/TLS Configuration: Since you mentioned a decryption error, double-check your SSL/TLS configuration for MongoDB. Ensure the
.pem
file path is correct and the file is accessible by your Node.js app.Nginx Reverse Proxy Setup: For Nginx, you’ll want to set up reverse proxy settings for your Node.js app. Here’s an example configuration snippet for your
/etc/nginx/sites-available/default
file:After updating, restart Nginx:
Logging and Monitoring: Keep an eye on both Nginx and Node.js logs for any errors that might provide more clues:
/var/log/nginx/error.log
If you are using a managed MongoDB cluster, you would need to make sure that your backend Droplet IP address is allowed in the trusted sources of the MongoDB cluster.
Keep us posted on your progress, and don’t hesitate to reach out for further assistance!
Best,
Bobby