简体   繁体   中英

Webserver instance cant connect to mongodb instance using aws ec2 linux: Connection refused

This is the first time using aws and linux.

I have setup a webserver with export MONGO_URL=mongodb://localhost:27017/app and its works but when I separate my mongodb into another aws instance and changed the localhost to my mongodb instance private ip address its doesnt works anymore.

I use telnet private-ip-add 27017 from webserver and it shows Connection refused

I have also set security group inbound on mongodb instance

Custom TCP Rule TCP 27017 webserver-private-ip-add/31

Can anyone help me? Thanks!

  1. Double-check the Security Group: Like you said, the EC2 instance must allow incoming TCP connections on port 27017 from either

    • the private IP network address other EC2 instance (eg 10.0.0.90/32 ),
    • or better, the ID of the Security Group, that belongs to the other (accessing) EC2 instance (eg sg-0d91740cb ).
  2. Double-check the MongoDB config file: Option net.bindIp must not be set to 127.0.0.1 but the local IP of your MongoDB EC2 instance. You could also bind to "everything" ( 0.0.0.0 ), but this might be slightly less secure (eg if Security Groups are not set up properly).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM