Play Framework 2 in production: HTTPS using nginx

If you provide some sort of user login on your page, you’ll probably want to use HTTPS/SSL. Play Framework 2 supports secure connections using the recommended setup with a reverse proxy such as nginx.

This means your application server will run your play framework application on a private port (the default is 9000), as well as an nginx web server which listens to the public ports (HTTP/80 and HTTPS/443), and redirects those requests back to your play app.

Nginx Configuration for HTTPS

Installing nginx on most linux distributions is usually a one-liner (please refer to the nginx documentation). Here is the configuration we use for setting up nginx as the reverse proxy. In this example we assume that your domain name is example.com and that your compiled Play application files (using play dist) are located in /var/example/target.

UPDATE: The some paths may have changed for Play Framework 2.3+ and later. See comments.

Checking for SSL in your play app

Note that in this example configuration, ALL traffic will use HTTPS. If you want to use both HTTP and HTTPS, you’ll have to remove the redirects from http to https. You can check in your play app which protocol the request uses:

Why? We’re using one that comes with Ubuntu, not sure which version exactly.

Djon Mayer

Documentation of PlayFramework says to HTTPServer next: “Note Make shure you are using version > 1.2 of Nginx otherwise chunked responses won’t work properly.”. I use Ubuntu Server 12.04 and Nginx is in Version 1.1.19 there.

http://blog.papauschek.com/ Christian Papauschek

We didnt run into issues with this one, probably because we
have proxy_buffering on;

This is done in order to use nginx’s caching capabilities in production (maybe ill write more about this in another post)

AGhost_7

In newer versions of play, I think that the path to compiled static assets is: