upstream puma_{{ redmine_user }} {
        server          unix:/home/{{ redmine_user }}/run/puma.sock fail_timeout=0;
}
server {
        server_name     {{ redmine_domain }};

        listen          0.0.0.0:80;
        listen          [::]:80;
        listen          0.0.0.0:443 ssl http2;
        listen          [::]:443 ssl http2;

        if ( $scheme = http ) {
            return      301 https://$server_name$request_uri;
        }

        include /etc/nginx/ssl/{{ redmine_user }}[.]conf;
        root            /home/{{ redmine_user }}/www/public;
        access_log      /var/log/nginx/{{ redmine_user }}_access.log;
        error_log       /var/log/nginx/{{ redmine_user }}_error.log;
        client_max_body_size 50M;

        include /etc/nginx/snippets/letsencrypt[.]conf;
        include /etc/nginx/snippets/errors-pages[.]conf;

        gzip on;
        gzip_disable "msie6";
        gzip_vary on;
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_http_version 1.1;
        gzip_types text/plain text/css application/json application/x-javascript application/javascript text/xml application/xml application/xml+rss text/javascript;

        location / {
                if (-f /home/{{ redmine_user }}/maintenance.lock) {
                        return 503;
                }
                if (!-f /home/{{ redmine_user }}/run/puma.pid) {
                        return 502;
                }
                try_files $uri @puma;
        }

        location @puma {
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header Host $http_host;
                proxy_redirect off;
                proxy_read_timeout 30;
                proxy_pass http://puma_{{ redmine_user }};
        }
}
