NodeJS Proxy via Apache
Here is how to serve nodejs entry points by using an Apache proxy. This hides the port number and the nodeJs entry points simply appear as part of the “monolithic” application.
WINDOWS:
Setup is easy:
Include "conf/extra/httpd-proxy.conf"
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
2.) Open your proxy config file C:\xampp\apache\conf\extra\httpd-proxy.conf
. Edit it to match the following:
<IfModule proxy_module>
<IfModule proxy_http_module>
ProxyRequests On
ProxyVia On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /node http://127.0.0.1:3000/
ProxyPassReverse /node http://127.0.0.1:3000/
</IfModule>
</IfModule>
3.) Open your vhosts file C:\xampp\apache\conf\extra\httpd-vhosts.conf
. Add the following:
<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass "/node" "http://127.0.0.1:3000/"
ProxyPassReverse "/node" "http://127.0.0.1:3000/"
ServerName api.impressto.net
</VirtualHost>
4.) Restart Apache.
from command terminal run:
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequest
sudo service apache2 restart
2.) Open vhosts file /etc/apache2/sites-available/api.impressto.net.conf
. Add the following:
<VirtualHost *:443>
ServerAdmin [email protected]
ServerName impressto.localhost
DocumentRoot /var/www/impressto.localhost/public
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8000/
ProxyPassReverse / http://127.0.0.1:8000/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/apache.key
<Directory /var/www/impressto.localhost/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
..