为什么';这个简单的Go服务器是否在Azure应用程序服务中运行?
我在为什么';这个简单的Go服务器是否在Azure应用程序服务中运行?,azure,go,azure-web-app-service,azure-app-service-envrmnt,Azure,Go,Azure Web App Service,Azure App Service Envrmnt,我在服务器中有此代码。转到: 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.
服务器中有此代码。转到:
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应用程序服务中运行Go web应用程序
有人能建议我做什么吗?我强烈建议您使用docker映像在azure应用程序服务上运行不受支持的语言:
支持的语言ASP.NET、ASP.NET核心、Java、Ruby、Node.js、PHP或Python
Github:
Docker图像
第一次运行需要一些时间,因为它会下载映像,您可以查看日志
结果
您的端口配置是否正确,以允许端口80上的入站流量?我相信是这样。在创建应用程序服务时,我从来没有为端口80设置过任何特定的设置。像这样使用go run
意味着每次处理程序启动时,它都将构建并运行您的代码。Go不是PHP或Ruby,你不应该用Go-run
做任何事情。你应该在你的工作站或构建服务器上构建
,并将编译好的二进制文件部署到你的服务器上(根本不需要安装)。@Adrian谢谢——我将web.config
文件改为调用我在本地构建并复制的server.exe
。这给了我一个502。几个月前,这个肯定对我有用。我刚回到项目中,突然间,这不起作用了。仍在尝试调试。希望你不必走集装箱路线。如果我有进展,我会在这里更新。如果这是我必须做的,我会试试。我只是想看看是否有可能在应用程序服务中直接调用标准的Go代码。嗨,阿纳斯,非常感谢你的示例!我会尝试一下。这是一个旧的,虽然没有标记为完成,我想保持这个开放,因为我非常想让一个围棋程序运行没有容器。仍然想知道为什么一个自给自足的本地Go程序在Azure应用程序服务中不起作用。