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

3

6

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.

Ofori answered 22/2, 2016 at 12:18 Comment(6)
Can you show your code that starts your http listener? Should be something like app.listen(port, address);Pyrenees
There are the following code in the app.js of mongo-express. server.listen(config.site.port, config.site.host, function () { config.site.port are set as follows in the config.js. port: process.env.VCAP_APP_PORT || 8081,Ofori
What AMI are you using? If it isn't Amazon Linux you may need to play with IPTablesAddams
@FuyuhikoSatou You still aren't giving enough information. What is the value for config.site.host? Is it localhost by any chance? I'm guessing you are only binding the listener to local traffic.Pyrenees
@Addams I am using Amazon Linux as AMI.Ofori
@MarkB Lack of information, I am sorry. Because certainly the value of config.site.host was 'localhost', this was changed to '0.0.0.0', was able to connect. Thank you!Ofori
O
8

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.

Ofori answered 23/2, 2016 at 3:51 Comment(0)
E
1

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
Ericson answered 31/1, 2021 at 10:23 Comment(0)
E
0

Default basicAuth credentials are admin:pass which can be changed through config.js

Elburr answered 5/10 at 5:38 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Gyrocompass

© 2022 - 2024 — McMap. All rights reserved.