# from https://github.com/fatiherikli/nginxparser/issues/17

server {
  listen 443 ssl;
  server_name prod.example.com example.com stage.example.com;

  ssl_certificate ssl.crt/example.com.crt;
  ssl_certificate_key ssl.key/example.com.key;

  keepalive_timeout 5;

  access_log /var/log/nginx/example.access.log;
  error_log /var/log/nginx/example.error.log;

  root /var/www/example/cs/current;

  client_max_body_size 20M;

  location / {
    try_files $uri $uri/index.html @cs_shared;
  }

  location /images {
    expires 30d;
  }

  location /scripts {
    expires 30d;
  }

  location /styles {
    expires 30d;
  }

  location @cs_shared {
    root /var/www/example/cs/shared/public;
    try_files $uri $uri/index.html @ss;
  }

  location @ss {
    root /var/www/example/ss/current/public;
    try_files $uri @index;
  }

  location @index {
    root /var/www/example/cs/current;
    rewrite ^ /index.html break;
  }

  location @rails {
    proxy_pass http://example-ror;

    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header Host $host;
    proxy_set_header X-Request-Start "t=${msec}";
    proxy_redirect off;

    proxy_read_timeout 300;

    proxy_buffer_size 16k;
    proxy_buffers 32 16k;

  }

  location ~* ^/(api|assets|system|rich|admin) {
    root /var/www/example/ss/current/public;
    try_files $uri @rails;
  }

  error_page 500 502 503 504 /500.html;
  location = /500.html {
    root /var/www/example/cs/current;
  }

  error_page 405 =200 $uri;

}
