MongoDB http interface is not working

June 30, 2014 4.8k views

Hello, i want to open MongoDB HTTP Interface ( http://docs.mongodb.org/ecosystem/tools/http-interfaces) but i can open http://188.226.225.xx:28017/news/news. I am add a rule to iptables :
sudo iptables -I INPUT -p tcp -m state --state NEW,ESTABLISHED --dport 27017 -j ACCEPT
But something wrong. Please. help ,me

1 comment
  • What I did was follow the instruction in the mongod.conf file

    $ sudo vim /etc/mongod.conf
    

    Comment the bind_ip value.

    # Listen to local interface only. Comment out to listen on all interfaces.
    # bind_ip = 127.0.0.1
    

    Save the file and restart mongod

    $ sudo service mongod restart
    

    Plus, i added iptable rule:

    $ sudo iptables -I INPUT -p tcp -m tcp --dport 27017 -j ACCEPT
    

    and save the rules

    $ sudo iptables-save
    

    That does the trick for me.
    Hope this help.

    -
    A

3 Answers

First, you need to check if there's anything listening on port 27017:

sudo netstat -plutn | grep 27017

If you see the mongodb process in the output and still can't access port 27017, try deleting the existing rule and adding the following rule instead:

sudo iptables -D INPUT -p tcp -m state --state NEW,ESTABLISHED --dport 27017 -j ACCEPT 
sudo iptables -I INPUT -p tcp -m tcp --dport 27017 -j ACCEPT
  • Results of "netstat -plutn | grep 27017"
    tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 17406/mongod

"mongod" is listening on 127.0.0.1:27017. Because it's listening on the local loopback interface (127.0.0.1), you will be able to connect to it only from the droplet itself. You need to set bindIp to 0.0.0.0 in /etc/mongodb.conf and restart MongoDB:

sudo service mongod restart
Have another answer? Share your knowledge.