1

I am running a nodejs application on my apache2 web server. On trying to access the domain page example.com it shows the default apache page instead of the apps page. But on going to example.com:8090 it show the node application

This is the config

<VirtualHost *80>
    ServerName example.com
    ServerAlias www.example.com

    ProxyRequests off
    ProxyPreserveHost On
    ProxyVia Full

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    <Location />
        ProxyPass http://serverip:8090
        ProxyPassReverse http://serverip:8090
    </Location>

</VirtualHost>

1 Answer 1

1

This will work, just know it's not ideologically the most elegant solution.

# Main site proxy
<VirtualHost *:80>
     ServerAlias www.example.com
     ServerName example.com
     ProxyPreserveHost On

     <Proxy *>
         Order allow,deny
         Allow from all
     </Proxy>
     ProxyPass / http://nodejsIP:8090/
     ProxyPassReverse / http://nodejsIP:8090/
</VirtualHost>



     # Subdomain proxies
     <VirtualHost *:80>
         ServerAlias www.api.example.com
         ServerName api.example.com
         ProxyPreserveHost On

         <Proxy *>
             Order allow,deny
             Allow from all
         </Proxy>
         ProxyPass / http://nodejsIP:8090/api/
         ProxyPassReverse / http://nodejsIP:8090/api/
     </VirtualHost>
     <VirtualHost *:80>
         ServerAlias www.apps.example.com
         ServerName apps.example.com
         ProxyPreserveHost On

         <Proxy *>
             Order allow,deny
             Allow from all
         </Proxy>
         ProxyPass / http://nodejsIP:8090/apps/
         ProxyPassReverse / http://nodejsIP:8090/apps/
     </VirtualHost>

Note: if your apache server and node server are both running off the same box and hence have the same IP, use http://localhost for the nodejsIP

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.