ProxyPass apache https to a node server

左心房为你撑大大i 提交于 2020-05-27 13:10:52

问题


I'm trying to make a apache server a gateway for my node server.
My apache will serve the static pages and the node will act as rest api server.
Both the node and the apache sits on the same server , ubuntu 64bit ec2.

I've tried to do this for https and failed, later i've tried to open up a http port for the proxy pass and it worked ( I've changed the node to be http in order for that to work).

my last resort will be turning the node to the web server, but I wish to keep it simple since it will go refactor soon and use meteor.

I'll appreciate any suggestion

This is my configuration for the 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

successfull http config

<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>

回答1:


SSLProxyEngine On needs to be declared to enable SSL for a reverse proxy config. This directive is documented here:

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




回答2:


The following config works for me. I used port 4433 however this is obviousy arbitrary

<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>



来源:https://stackoverflow.com/questions/34865193/proxypass-apache-https-to-a-node-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!