WordPress + CloudFront Flexible SSL最终陷入重定向循环(https)

编程入门 行业动态 更新时间:2024-10-21 17:42:30
本文介绍了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)

本文发布于:2023-10-31 16:20:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546620.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   CloudFront   WordPress   Flexible   https

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!