【问题标题】:Next JS Google Cloud App Engine SSL/HTTPSNext JS 谷歌云应用引擎 SSL/HTTPS
【发布时间】:2020-08-21 13:26:02
【问题描述】:

我有一个在 Google Cloud App Engine 中运行的简单无服务器 Next JS 应用程序。我配置了 SSL 证书,我可以通过访问我的 URL 来查看它是否有效。 IE。 https://example.com/ 但是,如果我访问 http://example.com/,它不会自动重定向到我的站点启用 HTTPS 的版本。

app.yaml -

runtime: nodejs
env: flex

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/nodejs/configuring-your-app-with-app-yaml
service: auto
handlers:
- url: /.*
  script: auto
  secure: always
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

【问题讨论】:

    标签: google-app-engine google-cloud-platform next.js


    【解决方案1】:

    您需要实现代码以通过 HTTP 重定向或强制 HTTPS,这在 the docs 中提到如下

    出于安全原因,所有应用程序都应鼓励客户端使用 https 连接。您可以使用 Strict-Transport-Security 标头来指示浏览器更喜欢 https 而不是 http。

    查看 Strict-Transport-Security 标头上的 this cheat sheet 以更好地了解它是什么以及它是如何工作的。还可以从另一个问题中查看this answer,它给出了很好的解释。

    最后这里是the guide关于如何实现它

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-13
      • 2014-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-09
      相关资源
      最近更新 更多