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.
It should be like
http://localhost:9000/P
You can't run two applications on the same port and it's not only Play's problem.
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.
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/;
}
}
and then start your first app at port 9021.
Do the same for other application(s), each time using other port.
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";