Mongodb 我能';不要从外面连接到mongo express
我用的是mongo express 安装在AWS EC2上,已启动Mongodb 我能';不要从外面连接到mongo express,mongodb,amazon-web-services,amazon-ec2,Mongodb,Amazon Web Services,Amazon Ec2,我用的是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
$ 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开放。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。在我的情况下,我遇到了问题,因为我想在另一个端口(4301)上公开我的容器 但快车仍在收听8081 要修复它,必须指定确实
VCAP\u APP\u主机
和VCAP\u APP\u端口
您可以在run cmd上直接指定它,如:
docker run——建立您的网络——命名您的\u MONGO\u EXPRESS\u容器\u name-e ME\u CONFIG\u MONGODB\u服务器=您的\u MONGO\u服务器\u IP-e VCAP\u应用程序\u主机=0.0.0.0-e VCAP\u应用程序\u端口=4301-p 4301:4301 MONGO EXPRESS
能否显示启动http侦听器的代码?应该类似于app.listen(端口、地址)代码>mongo express的app.js中有以下代码<代码>服务器.listen(config.site.port、config.site.host、函数(){
config.site.port在config.js中设置如下。port:process.env.VCAP|u APP|u port | 8081,
您使用的是什么AMI?如果不是Amazon Linux,您可能需要使用它IPTables@FuyuhikoSatou您仍然没有提供足够的信息。config.site.host的值是多少?是否有可能是localhost
?我是gUsing您只是将侦听器绑定到本地流量。@MarkB缺少信息,很抱歉。因为config.site.host的值肯定是“localhost”,所以它被更改为“0.0.0.0”,所以可以连接。谢谢!