我已经为在localhost上运行的节点服务器创建了一个反向代理,因此可以通过HTTPS提供服务 .
转发工作工作,但是当应用程序尝试发出请求时,我得到:
混合内容:'https://foo.com/'的页面是通过HTTPS加载的,但请求了一个不安全的XMLHttpRequest endpoints 'http:// localhost:8888 / graphql?query =%7Bnotifications(userid)%7Bid%2C ...此请求已被阻止;内容必须通过HTTPS提供 .
Vhost配置:
<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>
我的设置缺少什么?
2 回答
您正在
https://foo.com/
上打开页面,但页面中的网址包含硬编码的localhost
域和端口 . 在呈现页面时,客户端浏览器将尝试获取'http://localhost:8888/graphql
有效地跳过apache(在端口80上运行,在服务器foo.com
上)并直接命中您的节点应用程序,这将1)只有在您从同一台机器运行浏览器时才能工作您运行节点应用程序的地方,2)即使这样,您也会收到上述错误,因为某些页面资产是使用http
加载的 .当您使用相对URL(例如以
/
开头的URL)时,浏览器将添加基本URL,从而生成https://foo.com/graphql
.Absolute vs relative URLs
您需要将SSL证书添加到node.js应用程序 . 在apache上启用它赢得了't help since the apache is forwarding the requests to your node.js app on port 8888 (which communicates on plain http and not https). That' s为什么你得到混合内容错误 . 初始请求在apache上的 https 上,然后转发到 http 到node.js
使用SSL证书配置node.js应用程序的步骤(您可以使用自签名证书或商业证书) .
首先,您必须通过npm使用ssl-root-cas . 配置如下:
试试看看是否有效!