英文:
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请求,如果我不自己生成证书。
英文:
In GAE I just use a default domain name: https://*.appspot.com, so I don't need to generate self-signed certificates.
Google App Engine docs specify how app.yaml should be configured to serve SSL connections:
https://cloud.google.com/appengine/docs/standard/go/config/appref#handlers_secure
But to serve an HTTPS connection in Go I write the following code example where I need to specify the certificates' filenames:
import (
"net/http"
)
func main() {
go http.ListenAndServeTLS(Address, "cert.pem", "key.pem", nil)
}
I don't understand how in this case to serve SSL requests if I don't generate certificates myself.
答案1
得分: 3
你不需要在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")
}
英文:
You don't need to call http.ListenAndServeTLS
on App Engine. If you have your app.yaml
set up correctly, traffic will be served over SSL for you. A minimal App Engine app might be something like this:
package main
import (
"fmt"
"net/http"
)
func init() {
http.HandleFunc("/", handler)
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hi")
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论