Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying two different Play! applications on the same hostname

I have developed 2 applications with Play Framework, accessing different information, so it does not make sense to merge then as a single app.

Now I need to deploy both apps on the same hostname, each one in a separate sub-folder (URI), for example: example.com/payment/ example.com/cms/

And I am having problems with routes. I configured a nginx webserver to work as reverse proxy. It deliveries first page as expected.

But once I click anything, instead of going to /cms/Application/index it links back to /Application/index (without /cms/).

IMHO I believe I need change my routes file, hardcoding /cms/ on all paths, but it seems a bad approach because if I need to deploy the APP on another URI I will need to change routes again.

What is the best way to deploy two apps on the same hostname?

----- nginx.conf -----
...
...
...

    location /cms {
      proxy_pass      http://localhost:9001/;

      proxy_redirect          off;
      proxy_set_header        Host            $host;
      proxy_set_header        X-Real-IP       $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    location /payment {
      proxy_pass      http://localhost:9002/;

      proxy_redirect          off;
      proxy_set_header        Host            $host;
      proxy_set_header        X-Real-IP       $remote_addr;
      proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    }

...
...
...
----- nginx.conf -----
like image 201
arjones Avatar asked Jan 10 '11 21:01

arjones


People also ask

How can I host multiple apps under a single domain?

To host multiple apps under a single domain, I recommended you create an Azure Web App and deploy your web applications to each virtual directory with the name which could identify your web application.

How to host multiple applications in a single Azure App service?

Open the browser and type out the web app URL with the virtual pathname. Now using this technique, you can host as many applications as you want. In this article, we learned about hosting multiple applications in a single Azure App Service.

Can I deploy multiple webapps under one service plan?

You can deploy multiple separate ‘WebApps’ under an ‘App Service Plan’. All those WebApps (/websites) will have their own separate default domain (FQDN) and also you can set custom domain for each of those WebApps. Firstly, just to highlight on the terminology for more clarity:

How can I access multiple projects on the same server?

You should now be able to use meaningful URLs to access your different projects on the same server, without having to specify the port manually for each request. Note that this reverse proxy would also work using https (that’s what I’m personally up to).


1 Answers

If you take a look at this thread on the Google Groups, you will see that the preferred approach is to the the context path.

The recommendation is to use a bootstrap job to set the context per application in the following way

Play.ctxPath="/project1";
Router.detectChanges(Play.ctxPath);

So your code would be

Play.ctxPath="/cms";
Router.detectChanges(Play.ctxPath);

etc.

like image 176
Codemwnci Avatar answered Nov 15 '22 06:11

Codemwnci