问题描述
我有一个用C#编写的Microsoft Azure Function App 2.0预览版,该预览版绑定到
如何使它绑定到0.0.0.0而不是localhost,以便可以从本地网络上的另一台计算机访问它?
查看这些 Microsoft文档我可以在 local.settings.json
文件中看到如何指定端口主持人": {"LocalHttpPort":7071,"CORS":"*"}
但不使用哪个网络接口.
来自Rails背景,我可以这样做: rails s -b 0.0.0.0
如何在.net/Azure函数世界中做到这一点?
UPDATE—
您不再需要此方法,因为默认情况下,函数主机现在在 0.0.0.0:7071
上侦听:
$ func -v2.0.1-beta.33$ func |grep运行时函数运行时版本:2.0.11933.0$ func主机启动|grep -i听收听:http://0.0.0.0:7071
现在已弃用—
如果您使用的是Windows,
C:\> netsh接口portproxy add v4tov4 listenport = 8081 ^listenaddress = 0.0.0.0 connectport = 7071 connectaddress = 127.0.0.1C:\> netsh界面portproxy全部显示在ipv4上收听:连接到ipv4:地址端口地址端口--------------- ---------- --------------- ----------0.0.0.0 8081 127.0.0.1 7071C:\> netstat -an |的findstr 8081TCP 0.0.0.0:8081 0.0.0.0:0侦听C:\> netstat -an |的findstr 7071TCP 127.0.0.1:7071 0.0.0.0:0侦听
要测试:
C:\> curl.exe http://192.168.111.4:8081/api/HttpTrigger -iHTTP/1.1 200 OK日期:2018年3月28日,星期三,格林尼治标准时间内容类型:application/json;字符集= utf-8服务器:红est传输编码:分块哦,海."
要摆脱portproxy:
C:\> netsh接口portproxy删除v4tov4 listenport = 8081 listenaddress = 0.0.0.0
在Linux上,iptables可以通过它运行;在Mac上,iptables可以通过它运行……我不知道,nginx是您的出路吗?好的,似乎有一个 pfctl
工具,可能是继承的来自BSD?
尽管Kestrel是服务器,但是设置环境变量 ASPNETCORE_URLS ="http://*:7071"
无效.函数主机可能会在代码中以 localhost
引导,这可能暗示您不应该裸露它,而应该将代理反向添加到其中.
I have a Microsoft Azure Function App 2.0 preview written in C# which binds to http://localhost:7071.
How do I get it to bind to 0.0.0.0 instead of localhost so I can access it from another machine on my local network?
Looking at these Microsoft Docs I can see how to specify the port in the local.settings.json
file"Host": { "LocalHttpPort": 7071, "CORS": "*"}
But not which Network Interface to use.
Coming from a Rails background I would do this with: rails s -b 0.0.0.0
How do I do this in the .net / Azure Function world?
UPDATE —
You don't need this sorcery anymore as the functions host now listens on 0.0.0.0:7071
by default:
$ 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
NOW DEPRECATED —
If you're on 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
To test it out:
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."
To get rid of portproxy:
C:\>netsh interface portproxy delete v4tov4 listenport=8081 listenaddress=0.0.0.0
On Linux, iptables your way through it, on a Mac... i don't know, nginx your way out? Okay, there seems to be a pfctl
tool, probably inherited from BSDs?
Although Kestrel is the server, setting the environment variable ASPNETCORE_URLS="http://*:7071"
has no effect. The function host is probably bootstrapped with localhost
in code, which may be a hint that you're not supposed to expose it naked and you should reverse proxy into it.
这篇关于将Microsoft Azure Function App 2.0预览版绑定到0.0.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!