使用反向代理在 Windows Server IIS 上运行 Golang 服务器(配置 web.config)

问题描述 投票:0回答:1

我是 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>

https://alex.domenici.net/archive/deploying-a-go-application-on-windows-server-using-iis-and-a-reverse-proxy.

<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 服务器。第二部分反向代理到我已经启动的服务器。

我不确定配置文件中事件的发生顺序。

go iis web-config
1个回答
0
投票

Google 搜索“在 iis 中运行 golang”,我发现有两种方法可以实现你的目标:

  1. 将 Go 应用程序作为 Windows 服务运行。直接提供服务或通过反向代理(如 IIS ARR 模块)提供服务。
  2. 使用 httpPlatformHandler 在 IIS 后面运行 Go 应用程序。

对于 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" />  

参考文档:

https://learn.microsoft.com/en-us/iis/extensions/httpplatformhandler/httpplatformhandler-configuration-reference

https://learn.microsoft.com/en-us/previous-versions/azure/windows-server-azure-pack/mt125371(v=technet.10)

© www.soinside.com 2019 - 2024. All rights reserved.