# <%= app_name %> # upstream <%= app_name %>_backend {

server unix:/var/www/<%= app_name %>/tmp/sockets/unicorn.sock fail_timeout=0;

}

server {

listen 5.9.144.130:80;
server_name <%= app_name %>.fodojo.com;

access_log off;
error_log off;
server_tokens off;

root /var/www/<%= app_name %>/public;

try_files $uri $uri.html $uri/index.html /cache/$uri/index.html /cache/$uri.html /cache/$uri @app;

location ^~ /cache {
  return 404;
}

location ~ /\.[^\/]+ {
  return 404;
}

location @app {
  proxy_redirect     off;
  proxy_set_header   Host             $host;
  proxy_set_header   X-Real-IP        $remote_addr;
  proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
  # proxy_set_header X-Forwarded-Proto https; # for SSL, add this

  client_max_body_size       20m;
  client_body_buffer_size    128k;

  proxy_connect_timeout      90;
  proxy_send_timeout         90;
  proxy_read_timeout         90;

  proxy_buffer_size          4k;
  proxy_buffers              4 32k;
  proxy_busy_buffers_size    64k;
  proxy_temp_file_write_size 64k;

  proxy_pass http://<%= app_name %>_backend;
}

location ~ ^/(assets|uploads|images|javascripts|stylesheets)/ {
  expires 1y;
  add_header Cache-Control public;
  add_header Last-Modified "";
  add_header ETag "";
  break;
}

# This rewrites all the requests to the maintenance.html page if it exists in the doc root.
if (-f $document_root/system/maintenance.html) {
  return 503;
}

error_page 503 @503;
location @503 {
  root /var/www/<%= app_name %>/public;
  rewrite ^(.*)$ /system/maintenance.html break;
}

}