在 Google App Engine 中处理 HTTPS 请求
Go Handling HTTPS requests in Google App Engine
在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 请求。
您不需要在 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")
}
在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 请求。
您不需要在 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")
}