如何在 Google Cloud AppEngine 上强制使用 https

我正在尝试对 Google Cloud AppEngine 上托管的应用程序的所有流量强制使用 https。https 可以工作,但尽管遵循将 http 流量重写为 https 的说明,但仍然可以使用 http 访问该站点,这会导致问题。

我已将其添加到 app.yaml 中:

handlers:
  - url: /.*
    script: _go_app
    secure: always
    redirect_http_response_code: 301

但似乎没有什么区别。

我正在使用 julienschmidt 路由器,然后使用它来处理所有路由:

log.Fatal(fmt.Println(http.ListenAndServe(":8080", router)))

我已经考虑过使用 http.ListenAndServeTLS 但这需要额外的参数,并且我无法计算出这些值在 Google AppEngine 上下文中应该是什么。

log.Fatal(fmt.Println(http.ListenAndServeTLS(":8443", "cert.pem", "key.pem", router)))

“cert.pem”和“key.pem”在哪里?

我读过,我不需要在我的应用程序中显式提供 TLS,因为 AppEngine 会为我处理它,所以即使我知道参数是什么,我也不确定它是否有助于强制使用https

http://sapling.appspot.com
https://sapling.appspot.com
http://sapling.money
https://sapling.money

上述所有工作都有效,但我似乎无法将任何一个 http 版本强制为 https。


牛魔王的故事
浏览 81回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP