node.js - Apache ReverseProxy 不适用于 Node 和 SSL
问题描述
我正在尝试在 Web 服务器上的 HTTPS 上设置我的应用程序。我有一个使用 AutoSSL 安装在 InMotion 主机上的有效证书。我的节点应用程序在我的 Centos 服务器上的 3000 端口上运行,我的 apache SSL 服务器在端口 443 上运行。为了将请求路由到我的网站,我正在尝试创建一个反向代理。我制作了一个名为的文件,该文件default-site.conf
存储在其中/etc/http.d/conf.d
并具有以下内容:
<VirtualHost _default_:443>
SSLProxyEngine on
ServerName example.com
ServerAlias www.example.com
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
ServerAdmin info@example.com
DocumentRoot /home/USER/my-app/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /home/USER/ssl/certs/certificate.crt
SSLCertificateKeyFile /home/USER/ssl/keys/certificate.key
ProxyPass / https://example.com:3000/
ProxyPassReverse / https://example.com:3000 /
<Directory "/home/USER/my-app/public">
AllowOverride All
</Directory>
</VirtualHost>
我将强调该应用程序可以在http://example.com:3000
(不安全)访问,但是当我尝试转到https://example.com
(安全)时,我得到了一个 404 错误的空白 index.html:
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (index.js, line 0)
解决方案
我设法通过将我的配置完全简化为以下两行来解决这个问题:
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
这可能不是最灵活的方法,但它会按照我需要的方式重新路由流量,因此就我的目的而言,它可以工作。
推荐阅读
- cuda - 多路稳定隔断
- c# - 在 mvc 中使用 ajax 将日期传递给控制器
- scala - 将函数传递给没有括号参数的构造函数
- c# - 如何在 C# 中替换字符串中的多个子字符串?
- scheme - DrRacket 上的方案表达式错误,但在其他解释器上正确评估
- python - 零填充没有 numpy 的图像
- node.js - 如何将变量输入字符串?在一些文本之间?
- c++ - 为什么 2147453647*2147453647 的乘积在下面的 C++ 程序中显示 1 和 -2147453648*-2147453648 显示 0?
- python - selenium 中 'Select(driver.find_element_by_id('id_of_element')) 中的 id_by_element 是什么
- html - RegEx 仅接受 1900 年至 2019 年这种形式的年份 YYYY/YYYY/YYYY