是否有文档显示如何在 Google App Engine - 灵活的 PHP 上强制使用 HTTPS?
我尝试将 secure
放在 app.yaml 上,但没有成功。
我也尝试在 nginx-app.conf 中放置此内容,但没有成功。
我也尝试过
set $test "";
if ($http_x_forwarded_proto = 'http') {
set $test "http";
}
if ($test = 'http-non-cron') {
return 301 https://$host$request_uri;
}
我尝试过的其他选项
<?php
header("Strict-Transport-Security: max-age=31536000; includeSubDomains; preload");
exit();
?>
但没有运气。
最佳答案
使用以下代码(从比较中删除 -non-cron
):
set $test "";
if ($http_x_forwarded_proto = 'http') {
set $test "http";
}
if ($test = 'http') {
return 301 https://$host$request_uri;
}
如果您有 cron 处理程序,则必须使用如下配置允许这些处理程序进行 http 访问:
set $test "";
if ($http_x_forwarded_proto = 'http') {
set $test "http";
}
if ($request_uri != '/cron/') { # everything under /cron/
set $test "${test}-non-cron";
}
if ($test = 'http-non-cron') {
return 301 https://$host$request_uri;
}
关于php - 如何在 Google App Engine 灵活环境上强制使用 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49246049/