如何在Amazon Load Balancer后面修复Wordpress HTTPS问题?

编程入门 行业动态 更新时间:2024-10-24 16:23:31
本文介绍了如何在Amazon Load Balancer后面修复Wordpress HTTPS问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我以前遇到过这个问题。在Amazon的EC2负载均衡器后面运行Wordpress(或其他PHP脚本)时,脚本没有意识到它们是在https://协议上运行的,并导致诸如无限重定向循环和HTTPS警告之类的问题(有关此内容的一些内容)正在以非安全的方式请求页面...)。

I've had this issue before. When running Wordpress (or other PHP scripts) behind Amazon's EC2 Load Balancer, the scripts do not realize they are being ran on the protocol and results in issues such as endless redirect loops, and HTTPS warnings ("Some content on this page is being requested in a non-secure way...").

我在这里找到了一个解决方案,但需要修改Wordpress核心,这对可更新性没有好处: https ://wordpress/support/topic/when-behind-amazon-web-services-elastic-load-balancer-causes-endless-redirect

I found a solution here, but requires modifying Wordpress core, which is no good for updatability: wordpress/support/topic/when-behind-amazon-web-services-elastic-load-balancer-causes-endless-redirect

有没有办法解决这个问题,而无需修改Wordpress核心?我正在使用Apache 2.2。

Is there a way to fix this without modifying Wordpress core? I am using Apache 2.2.

推荐答案

正如您提供的链接所建议的那样,对于Wordpress,问题在于 is_ssl()函数,与大多数PHP软件一样,显式检查 $ _ SERVER ['HTTPS'] 和 $ _ SERVER ['SERVER_PORT'] 检查当前页面是否在https://上下文中被访问。

As the link you gave suggested, for Wordpress the issue lies in the is_ssl() function, which like most PHP software explicitly checks the $_SERVER['HTTPS'] and $_SERVER['SERVER_PORT'] to check if the current page is being accessed in the context.

当您的页面被访问时HTTPS,但亚马逊负载均衡器正在执行SSL卸载,并且实际上在非SSL端口80,网络服务器,PHP或其他任何内容上请求您的内容,不理解或看到它是通过https://访问的。

When your page is accessed over HTTPS, but the Amazon Load Balancer is performing SSL offloading and actually requesting your content on the non-SSL port 80, the webserver, PHP, or anything else for that matter, does not understand or see that it's being accessed over .

对此的修复是亚马逊的ELB发送事实上的标准 X-Forwareded-Proto HTTP header,我们可以用它来确定客户端在负载均衡器的另一端使用实际的协议。

The fix for this, is that Amazon's ELB sends the de-facto standard X-Forwareded-Proto HTTP header, which we can use to figure out which protocol the client is actually using on the other side of the Load Balancer.

使用Apache 2.2 ,你可以使用一些东西e行:

With Apache 2.2, you could use something along the lines of:

<IfModule mod_setenvif.c> SetEnvIf X-Forwarded-Proto "^https$" HTTPS </IfModule>

这只是读取 X-Forwared-Proto 标题,如果它等于 https ,则将 HTTPS 环境变量设置为 1 。 PHP将看到这个环境变量,最终它将变为 $ _ SERVER ['HTTPS'] 等于 1 - 就像它对真正的原生SSL请求一样。

This simply reads the X-Forwared-Proto header, and if it equals https then, sets the HTTPS environment variable to 1. PHP will see this environment variable, and eventually it will become $_SERVER['HTTPS'] that equals 1 -- just like it would be for a "real" native SSL request.

更多推荐

如何在Amazon Load Balancer后面修复Wordpress HTTPS问题?

本文发布于:2023-11-01 18:37:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550090.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   Amazon   Load   HTTPS   Wordpress

发布评论

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

>www.elefans.com

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