【问题标题】:Go Handling HTTPS requests in Google App Engine在 Google App Engine 中处理 HTTPS 请求
【发布时间】:2017-07-21 08:49:18
【问题描述】:

在 GAE 中我只使用默认域名:https://*.appspot.com,所以我不需要生成自签名证书。

Google App Engine 文档指定应如何配置 app.yaml 以提供 SSL 连接:

https://cloud.google.com/appengine/docs/standard/go/config/appref#handlers_secure

但是为了在 Go 中提供 HTTPS 连接,我编写了以下代码示例,我需要在其中指定证书的文件名:

import (
    "net/http"
)

func main() {
    go http.ListenAndServeTLS(Address, "cert.pem", "key.pem", nil)
}

如果我自己不生成证书,我不明白在这种情况下如何处理 SSL 请求。

【问题讨论】:

    标签: google-app-engine ssl go https ssl-certificate


    【解决方案1】:

    您无需在 App Engine 上调用 http.ListenAndServeTLS。如果您的app.yaml 设置正确,则会通过 SSL 为您提供流量。一个最小的 App Engine 应用可能是这样的:

    package main
    
    import (
        "fmt"
        "net/http"
    )
    
    func init() {
        http.HandleFunc("/", handler)
    }
    
    func handler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprint(w, "Hi")
    }
    

    【讨论】:

    • 谢谢!我会尽快检查的
    猜你喜欢
    • 1970-01-01
    • 2012-11-13
    • 2018-05-18
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-03
    相关资源
    最近更新 更多