Question

How does one get started with multiple domains using the Play Framework? In other words, the same server will serve content for both somedomain.com and anotherdomain.com, and both of these domain's content will be served by the Play Framework

Do you set up Play behind Apache for example, or can you configure virtual hosts on Play itself. I'm starting with a blank Linux server, and just want to know how to get started, i.e. should I mess about with things like Apache, or will I come right with the Play Framework alone?

Was it helpful?

Solution 2

Using front-end HTTP server is typical solution, otherwise you would need to access each application on the separate port and/or IP address.

Additionally HTTP servers allows you to work with SSL (Play 2.x doesn't support it!) so if you plan to create secure connections you will need to use scenario described in doc.

Finally using server will allow you to incorporate other useful things like load-balancing, serving static (really static) content in CDN-lke mode with very precise cache settings etc...

Just one tip: if only job for the HTTP server will be just proxying the Play apps, consider using some lighter option than Apache, for an example nginx or lighttpd, you'll find sample configurations for all of them in Play's documentation.

OTHER TIPS

As a follow-up to biesior's answer, using a front-end server appears to remain the best option as of 2.5.x (updated docs at https://www.playframework.com/documentation/2.5.x/HTTPServer).

That said, you could serve both domains with the same web application, detecting the intended host by pattern matching on request.headers.get("Host"). I've found it works reasonably well when "anotherdomain.com" is static and doesn't require any meaningful routing, but tread carefully.

I'll also note that recent versions of the Play Framework support https in a painless way once you have the necessary certs in your keystore (https://www.playframework.com/documentation/2.5.x/ConfiguringHttps). However, I can't see how one would make that play nicely with multiple domains.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top