Loopback: How to run multiple independent Loopback applications in a VPS server?

Created on 15 Sep 2017  路  1Comment  路  Source: strongloop/loopback

If we have several mobile apps with different Restful web services based on LoopBack and MongoDB how could we run these projects in same time in VPS to address mobile apps and web apps to connect and uses services.

It is not important that all web services using same port or different port numbers its important that we can address them differently, something like:

http://82.25.14.23/App1/api/Rerification
http://82.25.14.23/testapp2/api/registration
http://82.25.14.23/PazarWebApp/api/catagories

Most helpful comment

The question is more related to the server configuration itself, rather than Loopback. I do this in several production servers. Here are some tips:

  • In respect to Loopback, you only need to ensure that every application runs on a different port (i.e. 3000, 3001, 3002, etc)
  • Then you need to map this port to an address in your Apache or Nginx configuration. For example, this is virtual host configuration that I use this to run a development app:
<VirtualHost *:80>
    ServerName dev.example.com

    ProxyRequests Off

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

    ProxyPass / http://localhost:3001/
    ProxyPassReverse / http://localhost:3001
    ProxyPreserveHost on
</VirtualHost>

So that the Loopback app running at port 3001 will be mapped at dev.example.com.

  • Note that I am not using www.example.com/dev... Trust me it is generally better to use a subdomain, it is easier to mantain, easier to understand and easier to implement. You would end up with:

app1.example/api
testapp2,example.com/api
PazarWebApp.example.com/api

and so on...

If you want to use addresses like you mentioned look for "reverse proxy in subdirectory".

Hope these insights are helpful.

>All comments

The question is more related to the server configuration itself, rather than Loopback. I do this in several production servers. Here are some tips:

  • In respect to Loopback, you only need to ensure that every application runs on a different port (i.e. 3000, 3001, 3002, etc)
  • Then you need to map this port to an address in your Apache or Nginx configuration. For example, this is virtual host configuration that I use this to run a development app:
<VirtualHost *:80>
    ServerName dev.example.com

    ProxyRequests Off

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

    ProxyPass / http://localhost:3001/
    ProxyPassReverse / http://localhost:3001
    ProxyPreserveHost on
</VirtualHost>

So that the Loopback app running at port 3001 will be mapped at dev.example.com.

  • Note that I am not using www.example.com/dev... Trust me it is generally better to use a subdomain, it is easier to mantain, easier to understand and easier to implement. You would end up with:

app1.example/api
testapp2,example.com/api
PazarWebApp.example.com/api

and so on...

If you want to use addresses like you mentioned look for "reverse proxy in subdirectory".

Hope these insights are helpful.

Was this page helpful?
0 / 5 - 0 ratings