Apache reverse proxy to node.js server?
apache reverse proxy centos cpanel to node.js server
We are attempting to forward requests to a node.js application running on port 30026. We are using CentoOS 6.9 final.
We are working on a project that accepts requests from an Apache server and forwards them to a node.js application.
This is being hosted by Hostgator on a VPS.
Initially we were following instructions on how to write ProxyPass code to forward requests on the "/StudentSites" route to port 30026. We followed the instructions from the following article "bobbyiliev.com/blog/apache-reverse-proxy-centos-cpanel-server/" and wrote the code in example #1
We injected the following file into the httpd.conf file.
Example #1:
#/etc/apache2/conf.d/userdata/ssl/2_4/sitename/sitename.org/org.conf
#
However when we look at the http.conf file, the proxy code is written in the format below. We are confused on weather to follow the format below, or to follow the syntax from example #1. Can somebody confirm that we are putting these files in the correct location. Example #2: ##/usr/local/apache/conf/httpd.conf
We are guessing that we can forward all traffic on the /StudentSites route to our node server leaving all other traffic untouched. Are we on the right path here? Example #3 We also came across the following example for making these changes directly through the CPANEL GUI here
We have confirmed that the node.js app is available at 30026. Port 80 is still just loading the Apache default landing page. We need to know how to forward all traffic that lands on port 80 to our 30026 port (node.js app).
SSLProxyEngine on
ProxyPass "/StudentSites" "https://127.0.0.1:30026/"
ProxyPassReverse "/StudentSites" "https://127.0.0.1:30026/"
However when we look at the http.conf file, the proxy code is written in the format below. We are confused on weather to follow the format below, or to follow the syntax from example #1. Can somebody confirm that we are putting these files in the correct location. Example #2: ##/usr/local/apache/conf/httpd.conf
SecRuleEngine Off
RewriteEngine On
RewriteCond %{HTTP_HOST} =autodiscover.charlie.sitename.org [OR]
RewriteCond %{HTTP_HOST} =autodiscover.charlie.sitename.org:443
RewriteCond %{HTTP:Upgrade} !websocket [nocase]
RewriteRule ^ http://127.0.0.1/cgi-sys/autodiscover.cgi [P]
RewriteCond %{HTTP_HOST} =cpanel.charlie.sitename.org [OR]
RewriteCond %{HTTP_HOST} =cpanel.charlie.sitename.org:443
RewriteCond %{HTTP:Upgrade} !websocket [nocase]
RewriteRule ^/(.*) /___proxy_subdomain_cpanel/$1 [PT]
ProxyPass "/___proxy_subdomain_cpanel" "http://127.0.0.1:2082" max=1 retry=0
RewriteCond %{HTTP_HOST} =webdisk.charlie.sitename.org [OR]
RewriteCond %{HTTP_HOST} =webdisk.charlie.sitename.org:443
RewriteCond %{HTTP:Upgrade} !websocket [nocase]
RewriteRule ^/(.*) /___proxy_subdomain_webdisk/$1 [PT]
RewriteRule ^/(.*) /___proxy_subdomain_webdisk/$1 [PT]
ProxyPass "/___proxy_subdomain_webdisk" "http://127.0.0.1:2077" max=1 retry=0
RewriteCond %{HTTP_HOST} =webmail.charlie.sitename.org [OR]
RewriteCond %{HTTP_HOST} =webmail.charlie.sitename.org:443
RewriteCond %{HTTP:Upgrade} !websocket [nocase]
RewriteRule ^/(.*) /___proxy_subdomain_webmail/$1 [PT]
ProxyPass "/___proxy_subdomain_webmail" "http://127.0.0.1:2095" max=1 retry=0
RewriteCond %{HTTP:Upgrade} websocket [nocase]
RewriteCond %{HTTP_HOST} =cpanel.charlie.sitename.org [OR]
RewriteCond %{HTTP_HOST} =cpanel.charlie.sitename.org:443
RewriteRule ^/(.*) /___proxy_subdomain_ws_cpanel/$1 [PT]
RewriteCond %{HTTP:Upgrade} websocket [nocase]
RewriteCond %{HTTP_HOST} =webmail.charlie.sitename.org [OR]
RewriteCond %{HTTP_HOST} =webmail.charlie.sitename.org:443
RewriteRule ^/(.*) /___proxy_subdomain_ws_webmail/$1 [PT]
We are guessing that we can forward all traffic on the /StudentSites route to our node server leaving all other traffic untouched. Are we on the right path here? Example #3 We also came across the following example for making these changes directly through the CPANEL GUI here
We have confirmed that the node.js app is available at 30026. Port 80 is still just loading the Apache default landing page. We need to know how to forward all traffic that lands on port 80 to our 30026 port (node.js app).
-
We have confirmed that the node.js app is available at 30026. Port 80 is still just loading the Apache default landing page. We need to know how to forward all traffic that lands on port 80 to our 30026 port (node.js app).
Hello @bbessembinders, The third example you noted seems to work based on a customer report on the thread you linked: Can you confirm that you used that method and the default Apache page still loads? Have you tried using "http" for the destination URL like the example instead of "https" as listed in the output you provided? Thank you.0 -
Update: I had tried making changes to the config file with variations of http and https and Apache was still loading the index page, but the site was not forwarding traffic through to the proxy port after restarting the httpd service. I was looking in the config file "/usr/local/apache/conf/httpd.conf" and noticed that there is a setting in the config file for the Host IP that captures all traffic on port 443.
It looks like the HostIP VirtualHost directive supersedes any other directives from the sharedIP . Any changes that were made to the .27 VirtualHost external configuration file were not taking effect. I added the proxy settings to the HostIP external configuration file "/etc/apache2/conf.d/includes/post_virtualhost_global.conf" and the settings change does appear to have taken effect (The following code broke the Apache index page).ProxyPass / http://localhost:3001/ ProxyPassReverse / http://localhost:3001/
I made the following changes and the Apache index page is loading, but it is still not passing traffic to the desired port. I will need to continue to make adjustments to see if I can get the incoming traffic to pass to the desired port.ServerName example.org SSLProxyEngine on ProxyPass / http://localhost:30026/ ProxyPassReverse / http://localhost:30026/
Thanks for the suggestions. Any input is appreciated. I will update any progress made going forward.0 -
Hello @bbessembinders, You may also want to try adding the custom rules to all virtual hosts (instead of in the global post virtual host include) using the Apply to all virtual hosts on the system steps at: Modify Apache Virtual Hosts with Include Files - EasyApache 4 - cPanel Documentation Thank you. 0
Please sign in to leave a comment.
Comments
4 comments