首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >停靠瓶/ waitress.serve在本地网络中不可见

停靠瓶/ waitress.serve在本地网络中不可见
EN

Stack Overflow用户
提问于 2020-10-31 05:58:08
回答 2查看 428关注 0票数 0

我让服务器在docker下运行,并使用命令serve(app, listen='*:5000')启动它。

我可以:

  • 在两个127.0.0.1:5000localhost:5000下在容器中访问它
  • localhost:5000下从容器外部访问它

我不能:

  • 在“127.0.0.1:5000”下从外部容器访问它
  • 使用本地ip从本地网络访问它(这对我来说是最重要的)

我试图将本地地址传递到serve命令中,但它会引发错误,说明无法访问该地址。同时也尝试了host='0.0.0.0'。帮不上忙。

有人知道怎么让它在我的机器外面显眼吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-11-02 04:55:28

好的,我找到了一个解决方案,似乎能解决这个问题。问题是wsl。在github wsl回购,有一个设置桥的脚本。下面我发布代码,这样它就不会消失。贷给埃文迪亚斯

代码语言:javascript
复制
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';

if( $found ){
  $remoteport = $matches[0];
} else{
  echo "The Script Exited, the ip address of WSL 2 cannot be found";
  exit;
}

#[Ports]

#All the ports you want to forward separated by coma
$ports=@(80,443,10000,3000,5000);


#[Static ip]
#You can change the addr to your ip config to listen to a specific address
$addr='0.0.0.0';
$ports_a = $ports -join ",";


#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";

#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";

for( $i = 0; $i -lt $ports.length; $i++ ){
  $port = $ports[$i];
  iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
  iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
}
票数 0
EN

Stack Overflow用户

发布于 2020-10-31 06:05:25

如果您还没有这样做,请尝试公开端口5000。

这可以通过添加

代码语言:javascript
复制
EXPOSE 5000

去你的码头文件。您还需要在您的服务中有host='0.0.0.0‘,以便能够从本地网络访问您的页面。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64618861

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档