upstream huginn_app_server {
    # fail_timeout=0 means we always retry an upstream even if it failed
    # to return a good HTTP response (in case the Unicorn master nukes a
    # single worker for timing out).

    # for UNIX domain socket setups:
    server unix:/home/you/app/shared/pids/unicorn.socket;
}

server {
    listen 80;
    server_name your-domain.com;
    rewrite ^(.*) https://www.your-domain.com$1 permanent;
}

server {
    listen 80;
    server_name www.your-domain.com;
    rewrite ^(.*) https://www.your-domain.com$1 permanent;
}

server {
    listen 443;
    server_name your-domain.com;

    ssl on;
    ssl_certificate /etc/nginx/ssl-certs/your-domain.com.crt;
    ssl_certificate_key /etc/nginx/ssl-certs/your-domain.com.key.nopass;  

    rewrite ^(.*) https://www.your-domain.com$1 permanent;
}

server {
    listen 443;

    ssl on;
    ssl_certificate /etc/nginx/ssl-certs/your-domain.com.crt;
    ssl_certificate_key /etc/nginx/ssl-certs/your-domain.com.key.nopass;  
  
    client_max_body_size 4G;
    server_name www.your-domain.com;

    keepalive_timeout 5;

    # path for static files
    root /home/you/app/current/public;

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

    # Rails error pages
    error_page 500 502 503 504 /500.html;
    location = /500.html {
      root /home/you/app/current/public;
    }

    location @app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

      proxy_set_header X-Forwarded-Proto $scheme;

      proxy_set_header Host $http_host;

      proxy_redirect off;

      proxy_pass http://huginn_app_server;
    }
}