server {
  listen 80;
  server_name __hostname__;
  root /var/www/danbooru2/current/public;
  index index.html;
  access_log off;
  error_log off;
  client_max_body_size 35m;
  location /stylesheets {
    expires max;
    break;
  }
  location /javascripts {
    expires max;
    break;
  }
  location /data {
    # if you want to block hotlinking
    valid_referers none __hostname__ ~\.google\. ~\.bing\. ~\.yahoo\.;
    if ($invalid_referer) {
      return 403;
    }
    rewrite ^/data/sample/__.+?__(.+) /data/sample/$1 last;
    rewrite ^/data/__.+?__(.+) /data/$1 last;
    expires max;
    break;
  }

  location /maintenance.html {
    expires 10;
   }

  if (-f $document_root/maintenance.html) {
    rewrite ^(.*)$ /maintenance.html last;
    break;
  }

  location @app_server {
    proxy_pass http://app_server;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_redirect off;
    proxy_set_header Host $host:$server_port;
    proxy_set_header X-Forwarded-Proto $scheme;
  }

  location / {
    try_files $uri @app_server;
  }

  error_page 404 /404.html;
  error_page 500 502 503 504 /500.html;
}

upstream app_server {
  # server 127.0.0.1:9000;
  server unix:/tmp/.unicorn.sock;
}
