我是 Windows 服务器新手,但是,我在 Linux 方面有一些经验。
我正在尝试在 Windows 上运行一些 golang 服务器。他们在 Linux 上已经有一段时间了。
我正在使用以下链接中的示例作为我的
web.config
:
https://medium.com/@mossila/running-go-behind-iis-ce1a610116df
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\app.exe" />
</system.webServer>
</configuration>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:9000/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
一个示例将 golang 应用程序作为普通的 ASP.NET Core exe 应用程序运行。缺点是我必须在应用程序中使用
ASPNETCORE_PORT
才能获取准确的端口。
另一个在已经手动启动的 Golang 应用程序上使用反向代理。
我的挑战
我的挑战是将这两个
web.config
文件结合起来,以便第一部分启动我的 Golang 服务器。第二部分反向代理到我已经启动的服务器。
我不确定配置文件中事件的发生顺序。
Google 搜索“在 iis 中运行 golang”,我发现有两种方法可以实现你的目标:
对于 ASP.NET Core,处理请求的处理程序是 ASPNetCoreModule2。对于 Windows 上的 Node,它是 IISNode。对于所有其他使用 HTTPPlatformHandler。同样,对于 GoLang,推荐使用 HttpPlatformHandler 代理。
所以,最好的方法是使用这样的东西:
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath=".\app.exe" startupTimeLimit="60" />
参考文档: