map $http_upgrade $connection_upgrade {
       default upgrade;
       '' close;
}

server{
	listen $SWEBSOCKET_PORT ssl;
	ssl_certificate     $JC_CERT/fullchain.pem;
    ssl_certificate_key $JC_CERT/privkey.pem;

	location / {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_pass http://$NET$WEBSERVER:9000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
	        proxy_read_timeout 120s;
	}
}

server {
	listen 443 ssl;
	listen [::]:443 ssl;
	server_name $JC_SERVICE;
	ssl_certificate     $JC_CERT/fullchain.pem;
    ssl_certificate_key $JC_CERT/privkey.pem;

    location / {
        proxy_pass http://$SOUNDBASE_IP/;
        proxy_set_header Host '$SOUNDBASE_HOST';
        proxy_redirect http://$SOUNDBASE_HOST https://$JC_SERVICE;
        # kill cache
        add_header Last-Modified $date_gmt;
        add_header Cache-Control 'private no-store, no-cache, must-revalidate,  proxy-revalidate, max-age=0';
        if_modified_since off;
        expires off;
        etag off;
        # wait
        client_max_body_size 0;
        proxy_connect_timeout       6000;
        proxy_send_timeout          60000;
        proxy_read_timeout          6000;
        send_timeout                6000;

    }

    location  /pige {
        alias "$SOUNDBASE_DIR/pige";
        try_files $uri $uri/ =404;
    }


	location /direct.ogg {
		client_max_body_size 0;
		proxy_pass http://$NET$ICECAST:8000/direct.ogg;
        # kill cache
        add_header Last-Modified $date_gmt;
        add_header Cache-Control 'private no-store, no-cache, must-revalidate,  proxy-revalidate, max-age=0';
        if_modified_since off;
        expires off;
        etag off;
	}
	location /direct.mp3 {
		client_max_body_size 0;
		proxy_pass http://$NET$ICECAST:8000/direct.mp3;
    	add_header Cache-Control 'private no-store, no-cache, must-revalidate,  proxy-revalidate, max-age=0';
	}
    location /style.css {
        client_max_body_size 0;
        proxy_pass http://$NET$ICECAST:8000/style.css;
    }
    location /status.xsl {
        client_max_body_size 0;
        proxy_pass http://$NET$ICECAST:8000/status.xsl;
        # kill cache
        add_header Last-Modified $date_gmt;
        add_header Cache-Control 'private no-store, no-cache, must-revalidate,  proxy-revalidate, max-age=0';
        if_modified_since off;
        expires off;
        etag off;
    }


    location ~ /muxapi(/.*) {
        auth_basic "Entrez votre identifiant et mot de passe";
        auth_basic_user_file $SOUNDBASE_DIR/users.htpasswd;
        include uwsgi_params;
        uwsgi_param PATH_INFO "$1";
        uwsgi_param SCRIPT_NAME /muxapi;
        uwsgi_pass unix:/tmp/uwsgi/$JC_SERVICE/uwsgi-api.sock;
        client_max_body_size 0;
        proxy_connect_timeout       6000;
        proxy_send_timeout          60000;
        proxy_read_timeout          6000;
        send_timeout                6000;
        # kill cache
        add_header Last-Modified $date_gmt;
        add_header Cache-Control 'private no-store, no-cache, must-revalidate,  proxy-revalidate, max-age=0';
        if_modified_since off;
        expires off;
        etag off;
	}
}