WordPress + CloudFront Flexible SSL最终陷入重定向循环(https) [英] WordPress + CloudFront Flexible SSL ends up in redirect loop (https)

查看:125
本文介绍了WordPress + CloudFront Flexible SSL最终陷入重定向循环(https)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在CloudFront Flexible SSL后面进行设置时,通过https访问管理员时会遇到问题。

Having problems accessing the admin over https when it's setup behind CloudFront Flexible SSL.

通过http访问时,管理员可以正常工作,但是当我更改为安全后, https会在重定向循环中结束。

The admin works fine when accessing over http, but as soon as I change to secure https it ends up in a redirect loop.

我将以下行添加到 wp-config.php

define('FORCE_SSL_ADMIN', true);


推荐答案

这是因为CloudFlare的Flexible SSL可运行作为反向代理,并通过 http 连接到WordPress安装。 WordPress认为您正在通过 http 连接,并重定向到 https 资源。浏览器从CloudFlare请求 https 资源,CloudFlare再次从WordPress服务器通过 http 请求资源,从而导致另一个重定向。

This is due to the fact that CloudFlare's Flexible SSL operates as a reverse proxy and connects to the WordPress installation via http. Wordpress thinks you're connecting via http and does a redirect to the https resource. The browser requests the https resource from CloudFlare and CloudFlare again requests the resource over http from the WordPress server, resulting in another redirect.

幸运的是有一个解决方案。 CloudFlare发送一个HTTP标头X-FORWARDED-PROTO,这是从浏览器到CloudFlare服务器的连接中使用的协议。我们可以使用它来告诉WordPress,即使请求是通过 http 进行的,但浏览器的链接仍然是通过 https 。

Fortunately there's a solution. CloudFlare sends an http header X-FORWARDED-PROTO that is the protocol used in the connection from the browser to the CloudFlare server. We can use this to tell WordPress that even though the request is happening over http, the link to the browser is over https.

wp-config.php 文件中,添加以下行:

In the wp-config.php file add the following line:

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on';

同样重要的是,上一行位于下一行之前:

It's also crucial that the above line comes before the following line:

require_once(ABSPATH . 'wp-settings.php');

进行修改后,重定向循环将停止,您将可以再次使用管理员。

After making that modification the redirect loop will stop and you'll be able to use the admin again.

这最终适用于所有反向代理服务器,而不仅仅是CloudFlare。

This ultimately applies to all reverse proxy servers, not just CloudFlare.

这篇关于WordPress + CloudFront Flexible SSL最终陷入重定向循环(https)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆