首页 > 解决方案 > 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)

标签: node.jsapachereverse-proxy

解决方案


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

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

这可能不是最灵活的方法,但它会按照我需要的方式重新路由流量,因此就我的目的而言,它可以工作。


推荐阅读