Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bind无效 #6

Closed
crazyweeds opened this issue May 14, 2022 · 4 comments
Closed

bind无效 #6

crazyweeds opened this issue May 14, 2022 · 4 comments

Comments

@crazyweeds
Copy link

部署在公网服务器,然后设置:"listen": "0.0.0.0:8000",或者"listen": "WAN_IP:8000",都是无效的,导致公网服务访问。

@XZB-1248
Copy link
Owner

我的建议是:检查端口占用;或者把具体的错误贴上来。毕竟,只有描述很难找出原因。

@crazyweeds
Copy link
Author

说明一下,这是亚马逊服务器,有公网IP,不过ifocnfig不能直接看到公网IP。
方式1(能够正常启动):
配置文件:
{
"listen": "0.0.0.0:8001",
"salt": "tuttututututu",
"auth": {
"username": "nicaicaikan"
}
}
测试:telnet 127.0.0.1 8001 通过
测试:telnet 公网IP 8001 失败

方式2(无法正常启动):
配置文件:
{
"listen": "公网IP:8001",
"salt": "tuttututututu",
"auth": {
"username": "nicaicaikan"
}
}
[FTAL] 2022/05/15 04:58:45 Failed to bind address: listen tcp 公网IP:8001: bind: cannot assign requested address

@XZB-1248
Copy link
Owner

https://www.v2ex.com/t/788618

云服务器应该是有一层NAT,本机实际上应该没有直接绑定公网IP。
建议绑定0.0.0.0。
或者绑定ifconfig中能查到的内网IP(效果和绑定外网一致)。
再或者和我一样,localhost + nginx代理。

@XZB-1248
Copy link
Owner

再补充一下,来自阿里云:

弹性公网IP本质上是一个NAT IP。由于普通模式(NAT模式)下的公网IP存在于网关设备,并不在ECS实例的网卡上,所以在操作系统内看不到公网IP,只能看到网卡上的私网IP。

所以,实际上,服务器IP确实经过了NAT。
一般情况下,没办法直接绑定公网IP。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants