   server {
       listen 80;

	   server_name localhost;
	   root /usr/local/mediacp/htdocs;

	   access_log /usr/local/mediacp/log/nginx/proxy_access.log;
	   error_log /usr/local/mediacp/log/nginx/proxy_error.log error;

        client_max_body_size 250M;

        # Basic Rate limiting
        limit_req zone=global_req_limit_per_ip burst=100;
        limit_conn conn_limit_per_ip 20;
		include security.conf;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

		index index.html;

        location ~ ^/stream//?([^/]+)/?([^/]+)? {
            set $stream_url https://127.0.0.1:2020/system/proxy.php?slug=$1&unique_id=$1&mounturl=$2;

            proxy_buffering off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors off;
            proxy_redirect off;
            proxy_next_upstream error timeout invalid_header;
            proxy_pass_request_headers on;
            proxy_set_header Cache-Control no-cache;
            proxy_set_header                User-Agent "$http_user_agent [ip:$remote_addr]";
            proxy_set_header                X-Forwarded-For $remote_addr;
            proxy_connect_timeout 5;
            proxy_send_timeout 15;
            proxy_read_timeout 15;
            proxy_max_temp_file_size 0;
            proxy_pass $stream_url;
            expires off;
            client_max_body_size 1M;
            tcp_nodelay on;
        }

		include locations.conf;
		include vod.conf;

		try_files $uri @redirect;

		location @redirect {
			return 301 https://$host:2020$request_uri;
		}
   }
   server {
	   listen 443 ssl;
	   root /usr/local/mediacp/htdocs;

	   access_log /usr/local/mediacp/log/nginx/proxy_access.log;
	   error_log /usr/local/mediacp/log/nginx/proxy_error.log error;

	    ssl_certificate /usr/local/mediacp/content/certs/$ssl_server_name.crt;
	    ssl_certificate_key /usr/local/mediacp/content/certs/$ssl_server_name.key;

        client_max_body_size 250M;

        # Basic Rate limiting
        limit_req zone=global_req_limit_per_ip burst=100;
        limit_conn conn_limit_per_ip 20;
		include security.conf;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

		index index.php index.html;

        location ~ ^/stream//?([^/]+)/?([^/]+)? {
            set $stream_url https://127.0.0.1:2020/system/proxy.php?slug=$1&unique_id=$1&mounturl=$2;

            proxy_buffering off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors off;
            proxy_redirect off;
            proxy_next_upstream error timeout invalid_header;
            proxy_pass_request_headers on;
            proxy_set_header Cache-Control no-cache;
            proxy_set_header                User-Agent "$http_user_agent [ip:$remote_addr]";
            proxy_set_header                X-Forwarded-For $remote_addr;
            proxy_connect_timeout 5;
            proxy_send_timeout 15;
            proxy_read_timeout 15;
            proxy_max_temp_file_size 0;
            proxy_pass $stream_url;
            expires off;
            client_max_body_size 1M;
            tcp_nodelay on;
        }


		include locations.conf;
		include vod.conf;

   }
