Setting up Nginx for static content

Setting up Nginx for static content

In my last blog post you can read how to set up Nginx as a frontend server for a sample Play app. But what about
making Nginx listen to a custom folder? To serve some static files for example, outside of the Play folder?

Let's give it a try. In my situation, I need a custom folder for my static stuff, the location would be:


So I need to make Nginx listen to all the static requests leading to a static file in my uploads folder.

Let's spin up the text editor and load the Nginx configuration file:

open -a Atom /usr/local/etc/nginx/nginx.conf

And the only thing we need to add is the following:

location /uploads {
  alias /Users/acorovic/Sites/uploads;

Huhh?! I was expecting to see something like:

root: /Users/acorovic/Sites/uploads;

Well, me too, to be honest. But after reading some Stackoverflow questions,
I found out that we need to use alias instead of the root directive. After restarting Nginx you can serve static content from your custom folder.