在IIS上运行Go Web应用程序

huangapple go评论129阅读模式
英文:

Run go web application on IIS

问题

有没有办法在IIS上运行Go Web应用程序?
我在Azure上找到了一个设置,但在我的开发机上无法工作。
这是一个用于Azure的web.config配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
        </handlers>
        <httpPlatform processPath="d:\home\site\wwwroot\go\bin\go.exe" 
                      arguments="run d:\home\site\wwwroot\server.go" 
                      startupTimeLimit="60">
            <environmentVariables>
              <environmentVariable name="GOROOT" value="d:\home\site\wwwroot\go" />
            </environmentVariables>
        </httpPlatform>
    </system.webServer>
</configuration>
英文:

Is there a way to run Go web application on IIS?
I found a setting for azure but its not working on my dev machine
this is a web config for azure :

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;configuration&gt;
    &lt;system.webServer&gt;
        &lt;handlers&gt;
            &lt;add name=&quot;httpplatformhandler&quot; path=&quot;*&quot; verb=&quot;*&quot; modules=&quot;httpPlatformHandler&quot; resourceType=&quot;Unspecified&quot; /&gt;
        &lt;/handlers&gt;
        &lt;httpPlatform processPath=&quot;d:\home\site\wwwroot\go\bin\go.exe&quot; 
                      arguments=&quot;run d:\home\site\wwwroot\server.go&quot; 
                      startupTimeLimit=&quot;60&quot;&gt;
            &lt;environmentVariables&gt;
              &lt;environmentVariable name=&quot;GOROOT&quot; value=&quot;d:\home\site\wwwroot\go&quot; /&gt;
            &lt;/environmentVariables&gt;
        &lt;/httpPlatform&gt;
    &lt;/system.webServer&gt;
&lt;/configuration&gt;

答案1

得分: 9

您的本地IIS无法正常工作,原因是您需要安装一个名为HttpPlatformHandler模块的独立组件。

您可以通过以下链接下载和安装该模块:
https://azure.microsoft.com/zh-cn/blog/announcing-the-release-of-the-httpplatformhandler-module-for-iis-8/
http://www.iis.net/downloads/microsoft/httpplatformhandler

与以前的反向代理或FastCGI方法相比,这种新方法不再需要这些旧方法。

英文:

Your local IIS does not work simply because you need to install a separate component, called HttpPlatformHandler module,

https://azure.microsoft.com/en-us/blog/announcing-the-release-of-the-httpplatformhandler-module-for-iis-8/

http://www.iis.net/downloads/microsoft/httpplatformhandler

Reverse proxy or FastCGI were the older approaches which are no longer necessary with this new approach.

答案2

得分: 7

HttpPlatformHandler模块对我来说不起作用。我在Medium上找到了Sutean Rutjanalard的这篇文章,非常有帮助,他使用了ASP.NET Core模块。

基本上,你需要像在.NET Core应用程序中一样创建一个带有"无托管代码"的应用程序池。以下是web.config的内容:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
        </handlers>
        <aspNetCore processPath=".\YourGoApp.exe" />
    </system.webServer>
</configuration>
英文:

HttpPlatformHandler module doesn't work for me. I found this post by Sutean Rutjanalard on Medium very helpful, which use ASP.NET Core Module instead.

Basically, you need to create Application pool with "No Managed Code" as you do with a .net core app. And the following is the web.config.

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;configuration&gt;
    &lt;system.webServer&gt;
        &lt;handlers&gt;
            &lt;add name=&quot;aspNetCore&quot; path=&quot;*&quot; verb=&quot;*&quot; modules=&quot;AspNetCoreModule&quot; resourceType=&quot;Unspecified&quot; /&gt;
        &lt;/handlers&gt;
        &lt;aspNetCore processPath=&quot;.\YourGoApp.exe&quot; /&gt;
    &lt;/system.webServer&gt;
&lt;/configuration&gt;

huangapple
  • 本文由 发表于 2015年11月25日 20:39:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/33916771.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定