![](/img/trans.png)
[英]This request has been blocked; the content must be served over HTTPS error while making request from S3 to EC2 node endpoint
[英]Apache Reverse Proxy and localhost - “Mixed content, the content must be served over HTTPS”
我为在本地主机上运行的节点服务器创建了反向代理,以便可以通过HTTPS提供服务。
转发的工作效率很高,但是当应用尝试发出请求时,我得到了:
混合内容:“ https://foo.com/ ”上的页面已通过HTTPS加载,但请求了不安全的XMLHttpRequest终结点“ http:// localhost:8888 / graphql?query =%7Bnotifications(userid)%7Bid%2C ……该请求已被阻止; 内容必须通过HTTPS提供。
虚拟主机配置:
<VirtualHost *:443>
ServerName www.foo.com
ServerAlias foo.com
DocumentRoot /var/www/foo/
ErrorLog /var/www/foo/error.log
CustomLog /var/www/foo/requests.log combined
SSLEngine on
SSLProtocol all -SSLv2
SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
SSLCertificateFile "/etc/letsencrypt/live/foo.com/cert.pem"
SSLCertificateKeyFile "/etc/letsencrypt/live/foo.com/privkey.pem"
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:8888/
ProxyPassReverse / http://localhost:8888/
</VirtualHost>
我的设置中缺少什么?
您需要向您的node.js应用添加SSL证书。 在apache上启用它无济于事,因为apache将请求转发到端口8888上的node.js应用程序(该端口使用纯HTTP而非https进行通信)。 这就是为什么您会收到混合内容错误的原因。 最初的请求在apache上的https上,然后转发到http到node.js
使用SSL证书配置node.js应用程序的步骤(您可以使用自签名证书或商业证书)。
首先,您必须使用可通过npm获得的ssl-root-cas 。 对其进行如下配置:
'use strict';
var https = require('https')
, cas
;
// This will add the well-known CAs
// to `https.globalAgent.options.ca`
require('ssl-root-cas').inject();
cas = https.globalAgent.options.ca;
cas.push(fs.readFileSync(path.join(__dirname, 'ssl', '01-ssl-intermediary-a.pem')));
cas.push(fs.readFileSync(path.join(__dirname, 'ssl', '02-ssl-intermediary-b.pem')));
cas.push(fs.readFileSync(path.join(__dirname, 'ssl', '03-ssl-site.pem')));
尝试看看是否可行!
您正在https://foo.com/
上打开页面,但是页面中的URL包含硬编码的localhost
域和端口。 呈现页面时,客户端浏览器将尝试获取'http://localhost:8888/graphql
有效地跳过apache(在服务器foo.com
端口80上运行)并直接命中您的节点应用程序,这将1)起作用仅当您从运行节点应用程序的同一台计算机上运行浏览器时,并且2)即使那样,由于某些页面资产是使用http
加载的,您仍会收到上述错误。
当您使用相对URL(例如,以/
开头的URL)时,浏览器将在基础URL之前加上前缀,即https://foo.com/graphql
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.