首页 > 解决方案 > 多路复用路由器在 debian 拉伸(linux)上返回错误 503,适用于 Windows 10

问题描述

我在 Linux 服务器上遇到了一个奇怪的问题,当我运行我的应用程序并导航到它时,它给了我错误 503 服务不可用。

我正在使用 mux 路由器,它在 Windows 上运行良好,但在 Linux 上由于某种原因它不能。

我将路由传递给完成处理程序的中间件,就像这样......

中间件.go

func SetRoute(r *mux.Router, uri string, handle func(http.ResponseWriter, *http.Request), methods string) {
    r.HandleFunc(uri, handle).Methods(methods)
    r.Use(MiddlewareHandle)
}

func MiddlewareHandle(next http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        start := time.Now()

        defer func() {
            log.Println(r.URL.Path, time.Since(start))
        }()

        next.ServeHTTP(w, r)
    })
}

然后对于我的路线:

r := mux.NewRouter()

middleware.SetRoute(r, "/", index.Index, "GET")

srv := &http.Server{
    Handler:      r,
    Addr:         "127.0.0.1:8080",
    WriteTimeout: 15 * time.Second,
    ReadTimeout:  15 * time.Second,
}

log.Fatal(srv.ListenAndServe())

我的处理方式是这样的:

type IndexData struct {
    PageTitle   string
}

func Index(w http.ResponseWriter, r *http.Request) {
    data := IndexData{
        PageTitle:   "Hello World",
    }

    err := template.Must(template.New(BaseTemplate).Funcs(FuncTemplate).ParseFiles(BaseTemplate, "index.html")).ExecuteTemplate(w, "skeleton", data)
    if err != nil {
        fmt.Println(err)
    }
}

知道为什么它不能在 Linux (Debian Stretch) 上运行吗?

标签: go

解决方案


推荐阅读