本文介绍了引入ALB之后,发生了混合内容错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个EC2实例之前引入ALB(AWS上的Application Load Balancer)后,Chrome浏览器显示混合内容错误. (出于安全原因,我稍微修改了错误的内容)

After introducing ALB (Application Load Balancer on AWS) in front of one EC2 instance, Chrome browser shows Mixed Content Error. (I edited the content of the error a little by security reason)

Mixed Content: The page at 'https://www.sample.com/talk' was loaded
over HTTPS, but requested an insecure EventSource endpoint
'http://www.sample.com/api/getData?param1=123&param2=456'. This
request has been blocked; the content must be served over HTTPS.

Pattern1没有错误.

Pattern1 has no errors.

Pattern2显示以上错误.我不知道我的技术堆栈中有什么问题.

Pattern2 shows the above error. I don't know where is a problem in my technology stack.

Pattern1: ALB(443) => EC2(443)
Pattern2: ALB(443) => EC2(80)

我的技术栈:

ALB
Apache 2.4
Laravel 5.7
React 16.9

我尝试了以下解决方案,但错误仍然发生.

I tried the following solution but the error still happened.

  1. Laravel的信任代理.
  2. 从React向服务器的HTTP请求的编写方式类似于相对路径(/api/getData?param1 = 123& param2 = 456),因此我将代码替换为指定协议和域名的绝对路径( https://www.sample.com/api~ ).
  3. 在Apache Web服务器中,将http重写为https(我认为这是个坏主意).
  1. Trust Proxy of Laravel.
  2. HTTP request to server from React is written like relative path (/api/getData?param1=123&param2=456) so I replace the code to absolute path specifying protocol and domain name (https://www.sample.com/api~).
  3. In Apache web server, rewrite http to https (I think this is bad idea).

这是一个普遍的问题吗?

Is this a general problem?

如果您有任何提示,请帮助我.

If you have any hints, please help me.

对不起我的英语不好.

推荐答案

您遇到的问题与ALB无关,它只是一个传递负载平衡器,在一个端口上侦听并将请求转发到目标按您的配置进行分组.

The problem you are encountering has nothing to do with ALB, it is just a pass-through load balancer, listens on one port and forwards the requests to the target group as you configure.

由于内容混合,您的请求被浏览器阻止.如您所知,您需要使用相同的HTTPS或HTTP协议来提供内容.

Your requests are blocked by the browser due to the mixed content. As you understood you need to serve the contents using the same protocol either HTTPS or HTTP.

我可以想到两种可能性

  1. 您的应用程序代码/配置正在混淆内容
  2. 或者您的代理服务器(Apache)正在为端点切换协议

这篇关于引入ALB之后,发生了混合内容错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 13:14