php - 如何在 Google App Engine 灵活环境上强制使用 SSL

标签 php google-app-engine

是否有文档显示如何在 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/

相关文章:

php - Doctrine (symfony) YAML schema/fixture 约束问题

java - GAE 索引(再次)

Python:检查上传的文件是否为jpg

php - 文本区域中的换行符

php - 如何构造 PDOStatement 类?

php - 使用 mysqli_real_escape_string 是否足以保护我的查询字符串?

php - MySQLi 和 Phalanger

java - 使用 Blob 获取图像并保存到 Google App Engine

java - 使用 Java 设置 App Engine 数据存储区的光标

google-app-engine - 为静态 HTML 文件定义 CharSet