#user  nobody;
worker_processes  1;

error_log  logs/error.log;

events {
    worker_connections  1024;
}

http {
    upstream blazor {
        server localhost:50853;
        server localhost:81 backup;
    }

    server {
        listen       80;
        server_name  blazor.zone;
        client_max_body_size 20m;
        rewrite ^(.*)$  https://www.blazor.zone$1 redirect;
        proxy_redirect  off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    server {
        listen      443 ssl;
        server_name blazor.zone;
        rewrite ^(.*)$  https://www.blazor.zone$1 redirect;
        ssl_certificate cert/blazor.zone.cer;
        ssl_certificate_key cert/blazor.zone.key;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout 5m;
        ssl_ciphers     HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers   on;
        proxy_set_header    Host                $host;
        proxy_set_header    X-Real-IP           $remote_addr;
        proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto   $scheme;
        add_header          X-Frame-Options     SAMEORIGIN;
    }

    server {
        listen       80;
        server_name  www.blazor.zone;
        client_max_body_size 20m;
        rewrite ^(.*)$  https://$host$1 redirect;
        proxy_redirect  off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    server {
        listen      443 ssl;
        server_name www.blazor.zone;
        ssl_certificate cert/www.blazor.zone.cer;
        ssl_certificate_key cert/www.blazor.zone.key;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout 5m;
        ssl_ciphers     HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers   on;
        proxy_set_header    Host                $host;
        proxy_set_header    X-Real-IP           $remote_addr;
        proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
        proxy_set_header    X-Forwarded-Proto   $scheme;
        add_header          X-Frame-Options     SAMEORIGIN;
        proxy_intercept_errors on;
        error_page 404 500 502 /502.html;

        location / {
            proxy_connect_timeout  1;
            proxy_pass http://localhost:50853;
        }

        location /_blazor {
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_pass http://localhost:50853/_blazor;
        }

        location = /502.html {
            root html;
            internal;
        }
    }
}
