【问题标题】:ProxyPass apache https to a node serverProxyPass apache https 到节点服务器
【发布时间】:2016-04-24 05:48:12
【问题描述】:

我正在尝试将 apache 服务器作为我的节点服务器的网关。
我的 apache 将提供静态页面,节点将充当 rest api 服务器。
节点和 apache 都位于同一台服务器上,ubuntu 64bit ec2。

我尝试为 https 执行此操作但失败了,后来我尝试为代理通行证打开一个 http 端口并且它有效(我已将节点更改为 http 以使其工作) .

我最后的手段是将节点转换为网络服务器,但我希望保持简单,因为它很快就会重构并使用流星。

我会很感激任何建议

这是我对 apache 的配置

<VirtualHost *:443>

    ServerName secure.mysite.co.il
    ServerAdmin admin@mysite.com
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SSLEngine on
    SSLCertificateFile /ssl/mysite.crt
    SSLCertificateKeyFile /ssl/mysite.key
    SSLCertificateChainFile /ssl/ca-bundle-client.crt

    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass /echo/test https://127.0.0.1:8001/echo/test
    ProxyPassReverse /echo/test https://127.0.0.1:8001/echo/test

成功的http配置

<VirtualHost *:80>
    ServerAdmin admin@mysite.com
    ServerName mysite.co.il
    ServerAlias www.mysite.co.il
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass / http://127.0.0.1:8001/
    ProxyPassReverse / http://127.0.0.1:8001/
</VirtualHost>

【问题讨论】:

  • 您的节点服务是否配置了 SSL?
  • 它服务于相同的 ca var server = restify.createServer({ key: fs.readFileSync('/ssl/mysite.key'), certificate: fs.readFileSync('/ssl//mysite. crt'),名称:'mysite-rest',版本:'1.0.0' });
  • 我不明白 Node 如何同时为 https 和 http 连接设置端口 8001。您是否尝试过直接使用 OpenSSL(“openssl s_client -connect 127.0.0.1:8001”)测试 https 连接?
  • 正如我提到的“(我已将节点更改为 http 以使其正常工作)”。我刚刚删除了 crt 和密钥,使其仅用于测试 http
  • 不确定您是否意味着在 Apache 中禁用了它(只需将其更改为 http)或两者兼而有之。您能否再次在节点中启用它,尝试上面的 OpenSSL 命令,然后将该输出和您的完整节点应用程序添加到您的问题中。您的 Apache 配置看起来不错,因此怀疑是节点问题。

标签: node.js apache reverse-proxy mod-proxy http-proxy


【解决方案1】:

SSLProxyEngine On 需要声明为反向代理配置启用 SSL。该指令在此处记录:

http://httpd.apache.org/docs/2.2/mod/mod_ssl.html#sslproxyengine

【讨论】:

  • "请注意,SSLProxyEngine 指令通常不应包含在将充当转发代理的虚拟主机中(使用 指令。SSLProxyEngine 不需要启用转发代理服务器来代理 SSL/TLS 请求。"
  • BazzaDP,该语句适用于“forward”代理配置。 Tal 正在使用“reverse”代理(更常见).. 这确实需要 SSLProxyEngine On
  • 你是对的。把我的代理弄混了,检查了我自己的配置,但没有看到它,但现在确实看到了,显然早先检查错了。对我有好处:-)
【解决方案2】:

以下配置对我有用。我使用了 4433 端口,但这显然是任意的

<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 /var/www/example.com/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
    #SSLCertificateChainFile /etc/letsencrypt/live/fullchain1.pem


    ProxyPass / https://example.com:4433/
    ProxyPassReverse / https://example.com:4433 /

    <Directory "/var/www/example.com/public_html">
        AllowOverride All
    </Directory>        

</VirtualHost>

【讨论】:

    猜你喜欢
    • 2015-11-22
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    • 2017-01-18
    • 1970-01-01
    • 2013-04-02
    • 2020-08-03
    • 2021-09-08
    相关资源
    最近更新 更多