当前位置: > > > > 为什么这个简单的 Go 服务器不在 Azure 应用服务中运行?
为什么这个简单的 Go 服务器不在 Azure 应用服务中运行?
来源:stackoverflow
2024-04-20 10:18:35
0浏览
收藏
从现在开始,我们要努力学习啦!今天我给大家带来《为什么这个简单的 Go 服务器不在 Azure 应用服务中运行?》,感兴趣的朋友请继续看下去吧!下文中的内容我们主要会涉及到等等知识点,如果在阅读本文过程中有遇到不清楚的地方,欢迎留言呀!我们一起讨论,一起学习!
问题内容
我在 server.go 中有此代码:
package main
import (
"fmt"
"net/http"
"os"
)
func handler(w http.responsewriter, r *http.request) {
fmt.fprintf(w, "you just browsed page (if blank you're at the root): %s", r.url.path[1:])
}
func main() {
http.handlefunc("/", handler)
http.listenandserve(":"+os.getenv("http_platform_port"), nil)
}
还有这个 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>
这两个文件都位于 azure 应用服务的 d:\home\site\wwwroot 目录中。我还在 d:\home\site\wwwroot\go 中安装了 x64 windows go 运行时的 1.13.3 版本(从 go1.13.3.windows-amd64.zip 解压)。
当我浏览到 fwwebapi.azurewebsites.net/hello 时,它超时。
我从 http://www.wadewegner.com/2014/12/4-simple-steps-to-run-go-language-in-azure-websites/ 获取了这个样本,这无疑已经有几年了。但我希望能够在 azure 应用服务中运行 go web 应用程序。
谁能建议我能做什么?
解决方案
我强烈建议您使用 Docker 映像在 Azure 应用服务上运行不受支持的语言:
支持的语言 ASP.NET、ASP.NET Core、Java、Ruby、Node.js、PHP 或 Python
Github:
Docker 镜像
首次运行将需要一些时间,因为它会下载图像,您可以检查日志
结果
以上就是《为什么这个简单的 Go 服务器不在 Azure 应用服务中运行?》的详细内容,更多关于的资料请关注米云公众号!
