Setting up the Lighttpd web server with Play

Lighttpd (pronounced lighty) is another lightweight web server, similar to Nginx, as it also handles requests asynchronously. It is a matter of taste, and which web server you prefer, so this recipe is here for the sake of completeness.

The source code of the example application is available at examples/chapter7/ssl/example-app as well as for examples/chapter7/ssl/example-app-2 for the second application instance. The configuration files for the web server are put in examples/chapter7/lighttpd.

Getting ready

You should have a lighttpd installed on your system and have the the accesslog, proxy, and ssl modules enabled. When using a Debian derived operating system, you can use the lighttpd-enable-mod command, for example: lighttpd-enable-mod ssl.

How to do it...

Simple redirection works like this—put it into /etc/lighttpd/conf-enabled/10-proxy.conf:

$HTTP["host"] == "www.test.local" {
        proxy.server  = ( "" => ((
                 "host" => "192.168.0.2",
                 "port" => 9000
        )))
}

SSL is also set up pretty quickly; however, there is one major difference. Instead of having two different files for certificate and key file, you have to merge both files into one. Concatenate them together like this:

cat host.crt host.key > host.pem

Put your SSL specific configuration into /etc/lighttpd/conf-enabled/10-ssl.conf:

$SERVER["socket"] == "0.0.0.0:443" {
    ssl.engine     = "enable"   
    ssl.pemfile    = "/etc/nginx/host.pem"

    $HTTP["host"] == "www.test.local" {
        proxy.server  = ( "" => (
            (
                "host" => "192.168.0.2",
                "port" => 9000
            )
        ))
    }
}

As you might have already noticed, the proxy configuration looks as if you could put more than one host into it. Exactly this is the case, which makes configuration very simple. You can just enhance your current configuration to enable load balancing:

$HTTP["host"] == "www.test.local" {
        proxy.balance = "round-robin"
        proxy.server  = ( "" => (
                (
                 "host" => "192.168.0.2",
                 "port" => 9000
                ),
                (
                 "host" => "192.168.0.2",
                 "port" => 9001
                )
        ) )
}

How it works...

This configuration is by far the shortest, as it does most of the things which need to be done manually in Nginx and Apache configuration, automatically. There is no need to specify special redirect headers, and there is no need to specify special headers for SSL rewriting, as it's all implicit, which makes it by far the laziest solution.

If you are wondering about the somewhat strange configuration of proxy servers with the empty key for the servers, be aware that you can configure redirection for certain file extensions. This is actually pretty useless with a Play application. If you have designed nice looking URLs in your conf/routes file you will not have any file endings.

There's more...

Though lighttpd is not used as much as Apache or Nginx, you might want to consider it as a viable alternative in your web server landscape.

Learn more about lighttpd

You can find more information about lighttpd at http://www.lighttpd.net/, together with an impressive list of high performance sites currently using it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.47.218