Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I can't connect from the outside to the mongo-express

I am using the mongo-express.

Installed on AWS EC2, it was started.

$ node app
Mongo Express server listening on port 8081 at localhost
Database connected
Connecting to db...
Database db connected

However, it is not possible to connect from the browser to port 8081.

I can download the index.html of the mongo-express using wget command on ec2.

$ wget http://admin:pass@localhost:8081
--2016-02-22 02:22:25--  http://admin:*password*@localhost:8081/
Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:8081... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authentication selected: Basic realm="Authorization Required"
Reusing existing connection to localhost:8081.
HTTP request sent, awaiting response... 200 OK
Length: 9319 (9.1K) [text/html]
Saving to: ?index.html?

index.html            0%[                    ]       0  --.-KB/s               GET / 200 218.468 ms - 9319
index.html          100%[===================>]   9.10K  --.-KB/s    in 0.04s

2016-02-22 02:22:26 (236 KB/s) - ?index.html? saved [9319/9319]

By the way, port 8081 in the security group of ec2 is open to my IP.

like image 699
Fuyuhiko Satou Avatar asked Feb 22 '16 12:02

Fuyuhiko Satou


People also ask

Why is my MongoDB not connecting?

These are some of the solutions: Ensure that your MongoDB instance is running: Compass must connect to a running MongoDB instance. Also check you have installed MongoDB and have a running mongod process. You should also check that the port where MongoDB is running matches the port you provide in the compass connect.

How do I access Mongo Express?

To start working with Mongo Express you can now visit http://localhost:8081 or http://host-ip:8081 in your browser.

What is the difference between MongoDB and Mongo Express?

js (or simply Express) is a web application server framework for Node. js, and MongoDB is a general-purpose document database platform. You can use these together to build a web application that stores data in MongoDB. Since Express is a module running on top of Node.

How do I access MongoDB over HTTP on the native driver port?

MongoDB has an uncomplicated web-based central port at 28017 by default. At the default port of 27017, there is no HTTP access. The error port is used for native driver access, not HTTP traffic. To obtain MongoDB, you'll need to use a driver like the MongoDB essential driver for NodeJS.


2 Answers

The following settings of config.js is, was the cause

site: {    // baseUrl: the URL that mongo express will be located at - Remember to add the forward slash at the stard and end!
baseUrl: '/',
cookieKeyName: 'mongo-express',
cookieSecret:     process.env.ME_CONFIG_SITE_COOKIESECRET   || 'cookiesecret',
host:             process.env.VCAP_APP_HOST                 || 'localhost',
port:             process.env.VCAP_APP_PORT                 || 8081,
requestSizeLimit: process.env.ME_CONFIG_REQUEST_SIZE        || '50mb',
sessionSecret:    process.env.ME_CONFIG_SITE_SESSIONSECRET  || 'sessionsecret',
sslCert:          process.env.ME_CONFIG_SITE_SSL_CRT_PATH   || '',
sslEnabled:       process.env.ME_CONFIG_SITE_SSL_ENABLED    || false,
sslKey:           process.env.ME_CONFIG_SITE_SSL_KEY_PATH   || '',
},

The value of the host is changed to "0.0.0.0", now to be able to connect from browser to the mongo-express.

like image 95
Fuyuhiko Satou Avatar answered Nov 01 '22 17:11

Fuyuhiko Satou


In my case, I've got the issue because I wanted to expose my container on another port (4301).

But the express was still listening on 8081.

To fix it, had to specify indeed VCAP_APP_HOST and VCAP_APP_PORT.

And you can directly specify it on the run cmd like:

docker run --network YOUR_NETWORK --name YOUR_MONGO_EXPRESS_CONTAINER_NAME -e ME_CONFIG_MONGODB_SERVER=YOUR_MONGO_SERVER_IP -e VCAP_APP_HOST=0.0.0.0 -e VCAP_APP_PORT=4301 -p 4301:4301 mongo-express
like image 32
Emidomenge Avatar answered Nov 01 '22 16:11

Emidomenge