events {
  worker_connections  4096;  ## Default: 1024
}

http  {
    server {
        listen 8080;
        server_name localhost;


        # from https://medium.com/@dasirra/using-streamlit-nginx-docker-to-build-and-put-in-production-dashboards-in-aws-lightsail-781dab8f2836
        location ^~ /static {
            proxy_pass http://localhost:8501/static/;
        }
        location ^~ /healthz {
            proxy_pass http://localhost:8501/healthz;
        }
        location ^~ /vendor {
            proxy_pass http://localhost:8501/vendor;
        }
        location ^~ /st-allowed-message-origins {
            proxy_pass http://localhost:8501/st-allowed-message-origins;
        }

        # for jcloud deployment, very important; actually talks via websocket
        location ^~ /stream {
            # inspired from https://discuss.streamlit.io/t/how-to-use-streamlit-with-nginx/378/7
            proxy_pass http://localhost:8501/stream;
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_read_timeout 86400;
        }
        location ^~ /favicon.png {
            proxy_pass http://localhost:8501/favicon.png;
        }
        # to make extra components work
        location ^~ /component {
            proxy_pass http://localhost:8501/component;
        }

        location /playground {
            # streamlit specific from https://discuss.streamlit.io/t/streamlit-docker-nginx-ssl-https/2195
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_read_timeout 86400;
            proxy_pass http://localhost:8501;
            client_max_body_size 50M;
        }

        location / {
            proxy_pass http://localhost:8082;
            client_max_body_size 50M;
        }

     }
}