如何在同一端口的播放框架中运行多个应用程序 [英] HOw to run multiple applications in play framework on the same port

查看:79
本文介绍了如何在同一端口的播放框架中运行多个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Play Framework的新手.我正在使用Play 2.0.2,并且想在同一端口的Play上运行多个应用程序.

I am new to Play Framework. I am using Play 2.0.2 and I want to run multiple applications on Play on the same port.

应该像 http://localhost:9000/Project1/(controller)& http://localhost:9000/Project2/(controller)

It should be like http://localhost:9000/Project1/(controller) & http://localhost:9000/Project2/(controller)

我发现您可以在不同的端口上运行它,但是没有发现在同一端口上运行它的任何信息.

I have found that you can run it on different ports but found nothing regarding running it on the same port.

这有可能吗?

推荐答案

您不能在同一端口上运行两个应用程序,这不仅是Play的问题.

You can't run two applications on the same port and it's not only Play's problem.

使用前端HTTP服务器代理应用程序.如果您只需要运行Java应用程序,那么 nginx 是一个不错的选择您还需要根据Apache的特定功能与PHP系统配合使用,您可以使用 Apache代理也是

Use frontend HTTP server to proxy applications. If you have to run only java apps then nginx will be good choice, if you need to work also with PHP systems depending on Apache specific features you can use Apache proxy as well.

通常:您需要将服务器设置为侦听端口80,然后使用某些虚拟域(例如http://app1.lochttp://app2.loc等)为每个应用程序添加服务器块(Apache中的虚拟主机),然后将它们添加到您的hosts文件,以使它们在您的系统中可用.接下来,将每个服务器块配置为不同端口(nginx)上的应用程序的代理:

In general: you need to set the server to listen on port 80 and then add a Server Block (Virtual Host in Apache) for each application using some pseudo domains like http://app1.loc, http://app2.loc, etc add them to your hosts file, to make them available in your system. Next configure each Server Block to be a proxy for application on different ports (nginx):

server {
  server_name app1.loc www.app1.loc;
    listen 80;

    location / {
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:9021;
            proxy_redirect http://127.0.0.1:9021/ http://app1.loc/;
    }
}

,然后在9021端口启动您的第一个应用程序.

and then start your first app at port 9021.

每次使用其他端口对其他应用程序执行相同操作.

Do the same for other application(s), each time using other port.

最后要确保您始终在所需的端口9021上运行app1编写一个bash脚本(或Windows中的bat文件),该脚本将始终以相同的设置(即run.sh:

Finally to make sure, that you always running the app1 on required port 9021 write a bash script (or bat file in windows) which will run it always with the same settings i.e. run.sh:

#!/bin/bash
play "~run 9021";

这篇关于如何在同一端口的播放框架中运行多个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆