问题描述
我是 Play 框架的新手.我正在使用 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 likehttp://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.loc
、http://app2.loc
等将它们添加到您的 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";
这篇关于如何在同一个端口上在播放框架中运行多个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!