Virtual Host in Play Framework

Only available on StudyMode
  • Download(s) : 373
  • Published : September 2, 2012
Open Document
Text Preview
n play fr
Set-up a front-end HTTP server
You can easily deploy your application as a stand-alone server by setting the application HTTP port to 80: %production.http.port=80
But if you plan to host several applications in the same server or load balance several instances of your application for scalability or fault tolerance, you can use a front-end HTTP server. Note that using a front-end HTTP server will never give you better performance than using Play server directly! Set-up with lighttpd

This example shows you how to configure lighttpd as a front-end web server. Note that you can do the same with Apache, but if you only need virtual hosting or load balancing, lighttpd is a very good choice and much easier to configure! The /etc/lighttpd/lighttpd.conf file should define things like this: server.modules = (

$HTTP["host"] =~ "" {
proxy.balance = "round-robin" proxy.server = ( "/" =>
( ( "host" => "", "port" => 9000 ) ) )

$HTTP["host"] =~ "" {
proxy.balance = "round-robin" proxy.server = ( "/" => (
( "host" => "", "port" => 9000 ),
( "host" => "", "port" => 9001 ) )
Set-up with Apache
The example below shows a simple set-up with Apache httpd server running in front of a standard Play configuration. LoadModule proxy_module modules/

ProxyPreserveHost On
ProxyPass /
ProxyPassReverse /

Apache as a front proxy to allow transparent upgrade of your application The basic idea is to run 2 Play instances of your web application and let the front-end proxy load-balance them. In case one is not available, it will forward all the requests to the available one. Let’s start the same Play application two times: one on port 9999 and one on port 9998. Copy the application...
tracking img