server {
    server_name {{ fqdn }};
    listen 443 ssl http2;

    client_max_body_size 150M;

    ssl on;
    ssl_session_cache shared:SSL:50m;
    ssl_certificate           {{ ssl_certificate }};
    ssl_certificate_key       {{ ssl_key }};

    root {{ static_path }};
    index index.html index.htm;

    location /{% if multitenant_url %}{{ multitenant_url }}/{% endif %} {
        try_files $uri $uri/ /index.html;
    }

    location {% if multitenant_url %}/{{ multitenant_url }}{% endif %}/_api/ {
        proxy_pass http://localhost:{{ faraday_port }}/_api/;
        proxy_redirect http:// $scheme://;
        proxy_read_timeout 300;

        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Ssl on;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location {% if multitenant_url %}/{{ multitenant_url }}{% endif %}/websockets {
        proxy_http_version 1.1;
        proxy_pass http://localhost:{{ faraday_ws_port }}/websockets;

        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

server {
    server_name {{ fqdn }};
    listen 80 ;

    # https redirect
    if ($host = {{ fqdn }}) {
        return 301 https://$host$request_uri;
    }

    return 404;
}
