Virtual Host in Play Framework

Only available on StudyMode
  • Download(s) : 320
  • 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 = (

"mod_access",
"mod_proxy",
"mod_accesslog"
)
...
$HTTP["host"] =~ "www.myapp.com" {
proxy.balance = "round-robin" proxy.server = ( "/" =>
( ( "host" => "127.0.0.1", "port" => 9000 ) ) )
}

$HTTP["host"] =~ "www.loadbalancedapp.com" {
proxy.balance = "round-robin" proxy.server = ( "/" => (
( "host" => "127.0.0.1", "port" => 9000 ),
( "host" => "127.0.0.1", "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/mod_proxy.so
...

ProxyPreserveHost On
ServerName www.loadbalancedapp.com
ProxyPass / http://127.0.0.1:9000/
ProxyPassReverse / http://127.0.0.1:9000/

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