简体   繁体   English

将webapp2中的某些域的http重定向到https

[英]Redirect http to https for certain domains in webapp2

We use Google appengine namespaces for a mutli-tenant application. 我们将Google Appengine命名空间用于多租户应用程序。 Each tenant has a different domain. 每个租户都有一个不同的域。 Some of the domains need to have ssl enabled but some do not require ssl. 有些域需要启用ssl,但有些则不需要ssl。 For the domains that do require ssl, I'd like all old http links to redirect to their https equivalent. 对于确实需要ssl的域,我希望所有旧的http链接都重定向到其等效的https。

If we set secure: always in app.yaml, then the domains that do not require ssl (domains that don't have certificates) won't work as all requests are redirect to https. 如果我们将secure: always设置在app.yaml中,则不需要ssl的域(没有证书的域)将不起作用,因为所有请求都将重定向到https。

I assume I need to handle the redirect to https in webapp routing, depending on the domain requested. 我假设我需要在webapp路由中处理重定向到https的操作,具体取决于请求的域。 I've tried the "app_scheme" approach outlined here How to use WSGI to reroute a user from http to https but that doesn't handle redirects to https if accessing via http. 我尝试了此处概述的“ app_scheme”方法,该方法如何使用WSGI将用户从http重新路由到https,但是如果通过http访问,则无法处理到https的重定向。

Is there a way to handle redirect without re-writing all the DomainRoutes? 有没有一种方法可以处理重定向而无需重写所有DomainRoutes?

Alternate approach: you could have 2 apps, one for the http domains and one for the https domains, sharing the same app code except for the secure: always settings in the .yaml config files (achievable with a simple VCS repo branching strategy). 替代方法:您可能有2个应用程序,一个用于http域,一个用于https域,除了secure: always之外,它们共享相同的应用程序代码secure: always.yaml配置文件中进行设置(可通过简单的VCS回购分支策略实现)。 No rule re-writing required. 无需重写规则。

The 1st app is your current app unchanged, serving all http-only domains. 第一个应用程序是您当前的应用程序,未更改,可服务所有仅HTTP域。

The 2nd app is a clone of your existing app, with secure: always added in app.yaml . 第二个应用程序是您现有应用程序的副本,具有secure: always添加在app.yaml It will serve all https domains. 它将服务于所有https域。

You'd need to remove the https domains from the domain mappings of your 1st app and place them in the domain mapping of your 2nd app. 您需要从第一个应用程序的域映射中删除https域,并将其放置在第二个应用程序的域映射中。

You may also need to copy/move any datastore data pertinent to the https-only domains to the 2nd app since AFAIK the apps can't share the same datastore (it might be possible to share cloud storage between the 2 apps). 可能还需要复制/移动相关的HTTPS只域第二应用数据存储任何数据,因为据我所知的应用程序不能共享同一数据存储(有可能共享2个应用程序之间的云存储)。 Not 100% sure, I didn't yet attempt to share data between different apps. 不确定100%,我还没有尝试在不同应用之间共享数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM