Apache ReverseProxy无法与Node和SSL一起使用

时间:2020-02-02 00:02:23

标签: node.js apache reverse-proxy

我正在尝试在Web服务器上的HTTPS上设置我的应用程序。我有使用自动SSL在InMotion主机上安装的有效证书。我的Centos服务器上的端口3000上运行了节点应用程序,端口443上的Apache SSL服务器上运行了节点应用程序。为了将请求路由到我的网站,我试图创建一个反向代理。我制作了一个名为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(安全)时,我得到了空白index.html并显示404错误:

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (index.js, line 0)

1 个答案:

答案 0 :(得分:0)

我设法通过将配置完全简化为以下两行来解决此问题:

ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/

这可能不是最灵活的方法,但它会按照我需要路由的方式重新路由流量,因此对我来说,它是可行的。