【发布时间】:2020-02-21 02:48:22
【问题描述】:
我在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 中安装了1.13.3 版本的x64 Windows go 运行时(从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 App Services 中运行 Go Web 应用程序。
谁能建议我能做什么?
【问题讨论】:
-
您的端口是否正确配置为允许端口 80 上的入站流量?
-
我相信是的。在创建应用服务时,我不必为端口 80 设置任何特定内容。
-
像这样使用
go run意味着每次处理程序启动时都会构建并运行您的代码。 Go 不是 PHP 或 Ruby,你不应该使用go run做任何事情。您应该在您的工作站或构建服务器上go build,并将编译后的二进制文件部署到您的服务器(根本不需要安装 Go)。 -
@Adrian 谢谢——我将
web.config文件更改为调用server.exe,我在本地构建并复制了该文件。这给了我一个 502。 -
这在几个月前肯定对我有用。我刚刚回到该项目,突然这不起作用。仍在尝试调试。希望不必走集装箱路线。如果我有任何地方会在这里更新。
标签: azure go azure-web-app-service azure-app-service-envrmnt