gpt4 book ai didi

c# - 将 Microsoft Azure Function App 2.0 预览版绑定(bind)到 0.0.0.0

转载 作者:行者123 更新时间:2023-11-30 14:46:20 25 4
gpt4 key购买 nike

我有一个用 C# 编写的 Microsoft Azure Function App 2.0 预览版,它绑定(bind)到 http://localhost:7071 .

enter image description here

如何将其绑定(bind)到 0.0.0.0 而不是 localhost,以便我可以从本地网络上的另一台计算机访问它?

看看这些 Microsoft Docs我可以看到如何在 local.settings.json 文件中指定端口
“主持人”: {
“本地Http端口”:7071,
“CORS”:“*”
}

但不知道要使用哪个网络接口(interface)。

来自 Rails 背景的我会这样做:rails s -b 0.0.0.0

如何在 .net/Azure Function 世界中执行此操作?

最佳答案

更新-

你不再需要这个魔法了,因为函数主机现在正在监听 0.0.0.0:7071默认情况下:

$ func -v
2.0.1-beta.33

$ func | grep Runtime
Function Runtime Version: 2.0.11933.0

$ func host start | grep -i listen
Listening on: http://0.0.0.0:7071
<小时/>

现已弃用 -

如果您使用的是 Windows,

C:\>netsh interface portproxy add v4tov4 listenport=8081 ^
listenaddress=0.0.0.0 connectport=7071 connectaddress=127.0.0.1


C:\>netsh interface portproxy show all

Listen on ipv4: Connect to ipv4:
Address Port Address Port
--------------- ---------- --------------- ----------
0.0.0.0 8081 127.0.0.1 7071


C:\>netstat -an | findstr 8081
TCP 0.0.0.0:8081 0.0.0.0:0 LISTENING

C:\>netstat -an | findstr 7071
TCP 127.0.0.1:7071 0.0.0.0:0 LISTENING

测试一下:

C:\>curl.exe http://192.168.111.4:8081/api/HttpTrigger -i
HTTP/1.1 200 OK
Date: Wed, 28 Mar 2018 18:25:31 GMT
Content-Type: application/json; charset=utf-8
Server: Kestrel
Transfer-Encoding: chunked

"Oh hai."

要摆脱 portproxy:

C:\>netsh interface portproxy delete v4tov4 listenport=8081 listenaddress=0.0.0.0

在 Linux 上,iptables 是你的出路,在 Mac 上……我不知道,nginx 是你的出路吗?好吧,好像有一个 pfctl 工具,可能是从 BSD 继承的?

虽然Kestrel是服务器,但设置环境变量ASPNETCORE_URLS="http://*:7071"没有影响。函数主机可能是用 localhost 引导的在代码中,这可能暗示您不应该裸露它,您应该反向代理到它。

关于c# - 将 Microsoft Azure Function App 2.0 预览版绑定(bind)到 0.0.0.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49539282/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com