nginx configuration for PlayFramework static files

nginx, playframework, playframework-2.0, scala

Solution

Assuming the play app is running on the same machine as Nginx - and is listening on port 9000

upstream play_app  {
  server 127.0.0.1:9000;
}

server {
  listen 80;
  location / {
     proxy_pass  http://play_app;
  }
}

This will route all requests from port 80 via nginx - to the play app on the same machine on port 9000.

If you wish for NGinx to serve your local assets - add a second location before the catch all rule.

server {
  listen 80;
  location /assets {
    root /var/www;
  }
  location / {
     proxy_pass  http://play_app;
  }
}

Problem

I want to use Nginx to server /assets folder for my Play! application. I would like to: - Proxy most files to Play! - Point /assets to a local folder I am using the following configuration, but it's not working: ``` worker_processes 1; error_log logs/error.log; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; upstream play_app { server 0.0.0.0:9000; } server { listen 80; location / { proxy_pass http://play_app; } } } ``` Also, if I get this working, will I be able to write to Nginx /assets folder from play via `Play.getFile("/assets/images")` ?

Original source