Report this

What is the reason for this report?

Apache: How to create a sub-directory which would serve node.js app running on a port?

Posted on April 17, 2019

I am trying setup Apache to have multiple routes/links/sub-directory for multiple apps (node.js app, react app)

For example,

mydomain.net/projects/app1

mydomain.net/projects/app2

And these apps would start on its individual ports like app1 runs on port 81, app2 runs on port 82,… and so on.

I had already try to create a virtualhost in /etc/apache2/sites-available/newRoute.conf

<VirtualHost *:80>

        ServerName mydomainname.net
        ServerAlias www.mydomainname.net
        ServerAdmin name@hotmail.com

        RewriteEngine On
        RewriteCond %{HTTP:Upgrade} =websocket [NC]
        RewriteRule /(.*)                       ws://localhost:3000/$1 [P,L]
        RewriteCond %{HTTP:Upgrade} !=websocket [NC]
        RewriteRule /(.*)                       http://localhost:3000/$1 [P,L]

        ProxyPassReverse / http://localhost:3000/

</VirtualHost>

<VirtualHost *:80>

        ServerName mydomainname.net/test
        ServerAlias www.mydomainname.net/test
        ServerAdmin name@hotmail.com

        ProxyPass /test http://localhost:81/
        ProxyPassReverse /test http://localhost:81/

</VirtualHost>

but it didn’t work out. I started the node.js app on port 81 and browse to mydomainname.net/test, and it just display my mydomainname.net content.

In addition, localhost:3000 is just a react app which has homepage content

Also, the node.js app which running on localhost:81 would print “hello world” on the screen.

Thank



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

@chiKaRauT Use Location tag as follows

<VirtualHost *:80>

        ServerName mydomainname.net
        ServerAlias www.mydomainname.net
        ServerAdmin name@hotmail.com

       <Location /projects/app1>
             ProxyPass http://localhost:81/
      </Location>

       <Location /projects/app2>
             ProxyPass http://localhost:82/
      </Location>

</VirtualHost>

Hope this helps.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.