Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Apache reverse proxy to node.js server?

Discussion in 'Workarounds and Optimization' started by bbessembinders, Jul 29, 2018.

  1. bbessembinders

    bbessembinders Registered

    Joined:
    Jul 13, 2018
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    United States
    cPanel Access Level:
    Root Administrator
    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
    #

    Code:
    <VirtualHost *:80>
    
        SSLProxyEngine on
        ProxyPass "/StudentSites" "https://127.0.0.1:30026/"
        ProxyPassReverse "/StudentSites" "https://127.0.0.1:30026/"
    
    </VirtualHost>
    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

    Code:
    <Proxymatch ^https?://127\.0\.0\.1:(2082|2083|2077|2078|2079|2080|2086|2087|2095|2096)/>
       <IfModule security2_module>
          SecRuleEngine Off
       </IfModule>
    </Proxymatch>
    
    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
    Make NodeJS service with git repos

    Code:
    <VirtualHost xxx.xxx.xxx.xxx:80>
        ServerName sitename.org
        ProxyPreserveHost On
        ProxyPass "/StudentSites" "https://127.0.0.1:30026/"
        ProxyPassReverse "/StudentSites" "https://127.0.0.1:30026/"
    </VirtualHost>
    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).
     
    #1 bbessembinders, Jul 29, 2018
    Last edited by a moderator: Jul 29, 2018
  2. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,827
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Hello @bbessembinders,

    The third example you noted seems to work based on a customer report on the thread you linked:

    Make NodeJS service with git repos

    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice