gpt4 book ai didi

azure - 为什么这个简单的 Go 服务器不在 Azure 应用服务中运行?

转载 作者:行者123 更新时间:2023-12-01 22:33:08 25 4
gpt4 key购买 nike

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

这两个文件都在 d:\home\site\wwwroot Azure 应用服务的目录。我也有 1.13.3go1.13.3.windows-amd64.zip 中安装的 x64 Windows go 运行时版本(从 d:\home\site\wwwroot\go 解压缩) .

当我浏览到 fwWebApi.azurewebsites.net/hello它超时。

我从 http://www.wadewegner.com/2014/12/4-simple-steps-to-run-go-language-in-azure-websites/ 得到了这个样本诚然,这已经有几年的历史了。但我希望能够在 Azure App Services 中运行 Go Web 应用程序。

谁能建议我能做什么?

最佳答案

我强烈建议您使用 docker 镜像在 azure 应用服务上运行不支持的语言:

支持的语言 ASP.NET、ASP.NET Core、Java、Ruby、Node.js、PHP 或 Python

Github:https://github.com/AnassKartit/helloworld-golang

docker 形象
https://hub.docker.com/r/anasskartit/hello-world-golang

首次运行需要一些时间,因为它会下载图像,您可以查看日志

enter image description here

enter image description here

结果
enter image description here

关于azure - 为什么这个简单的 Go 服务器不在 Azure 应用服务中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58546842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com