worker_processes 1;

events {
    worker_connections 1024;
}

http {
    # Redirect HTTP to HTTPS
    server {
        listen 80;
        listen [::]:80;
        server_name _;
        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl;
        server_name localhost;

        gzip on;
        gzip_min_length 2000;
        gzip_proxied any;

        proxy_read_timeout 60s;
        client_max_body_size 64M;

        ssl_certificate server.pem;
        ssl_certificate_key server.key;

        ssl_session_cache builtin:1000  shared:SSL:10m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
        ssl_prefer_server_ciphers on;

        location / {
            error_page 418 = @proxy_to_app;
            return 418;
        }

        location @proxy_to_app {
            proxy_pass http://devpi:3141;
            proxy_pass_header Authorization;
            proxy_redirect off;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Outside-URL $scheme://$host:$server_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Host $server_name;
        }
    }
}
