我无法从外部连接到 mongo-express

问题描述 投票:0回答:3

我正在使用 mongo-express。

安装在AWS EC2上,已启动。

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

但是,无法从浏览器连接到端口 8081。

我可以在ec2上使用wget命令下载mongo-express的index.html。

$ 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]

顺便说一句,ec2安全组中的8081端口对我的IP开放。

mongodb amazon-web-services amazon-ec2
3个回答
8
投票

config.js的以下设置,是原因

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   || '',
},

主机的值更改为“0.0.0.0”,现在能够从浏览器连接到 mongo-express。


1
投票

就我而言,我遇到了这个问题,因为我想在另一个端口(4301)上公开我的容器。

但快车仍在监听8081。

要修复它,必须确实指定

VCAP_APP_HOST
VCAP_APP_PORT

你可以直接在运行cmd上指定它,例如:

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

0
投票

默认的 basicAuth 凭据是 admin:pass ,可以通过 config.js 更改

© www.soinside.com 2019 - 2024. All rights reserved.