mongodb如何更改默认端口 [英] mongodb how to change default port

查看:1870
本文介绍了mongodb如何更改默认端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的项目,我需要在端口80上使用mongodb. 实际上,我不能使用默认的mongodb端口(27017). 我必须使用端口80.

For my project I need to use mongodb on port 80. In fact I can't use the default mongodb port (27017). I must use port 80.

如果我编辑配置文件:

sudo nano /etc/mongodb.conf

将端口更改为80,然后重新启动mongodb服务,当我尝试连接到mongodb时收到此消息

and I change the port to 80 then I restart mongodb service, I get this message when I try to connect to mongodb

$ mongo --port 80

MongoDB shell version: 2.4.9
connecting to: 127.0.0.1:80/test
Fri Feb  6 14:16:42.705 Error: couldn't connect to server 127.0.0.1:80 at src/mongo/shell/mongo.js:147
exception: connect failed

如果我再次将端口更改为27017,则一切正常.

If I change the port again to 27017, all work fine.

有人可以帮助我吗?

推荐答案

检查端口是否已被其他应用程序或服务打开:

Check if port is already open by another application or service:

在Windows上,打开cmd并键入:netstat -a

on Windows, open cmd and type: netstat -a

在Linux上,输入:netstat -lptn

on Linux, type: netstat -lptn

寻找开放端口80,例如TCP 0.0.0.0:80

Look for open port 80, like TCP 0.0.0.0:80

如果找不到它,请打开mongodb.conf并更改net部分:

If you can't find it, open mongodb.conf and change the net section:

net:
   bindIp: 127.0.0.1
   port: 80

希望对您有帮助

这篇关于mongodb如何更改默认端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆