upstream unicorn {
  server unix:/tmp/unicorn.PadmakaraDownloader.sock fail_timeout=0;
}

server {
  listen 80 default deferred;
  server_name digital.padmakara.com;
  root /home/jeremy/public_html/PadmakaraDownloader/current/public;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  location /protected/ {
    internal;
    alias /home/jeremy/public_html/PadmakaraDownloader/shared/data/;

    # Disable compression (if we are sending compressed files)
    gzip off;

    # Do not cache files larger than 100m; send directly, disabling sendfile
    directio 100m;

    # 2 output buffers, 512k each; improves disk IO for files > 100m
    output_buffers 2 512k;

    # Limit requests and transfer rates
    # limit_req zone=alpha burst=20;
    # limit_rate 750k;

    # Hotlink protection and redirection; disallow linking to your files and return a 403 error
    valid_referers none blocked server_names;
    if ($invalid_referer) {
        rewrite /protected/ /;
    }
  }

  try_files $uri/index.html $uri @unicorn;
  location @unicorn {
    proxy_redirect off;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;

    proxy_set_header X-Sendfile-Type X-Accel-Redirect;

    proxy_pass http://unicorn;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 10;
}