server {
	listen 80;
	server_name {{ server_name }};
	rewrite ^ https://$host$request_uri? permanent;
}

server {
	listen 443 ssl;
	server_name {{ server_name }};

	root /var/www/streaming/;

	access_log /var/log/nginx/access_streaming.log;
	error_log /var/log/nginx/error_streaming.log;

	location /crossdomain {
	}

	location / {
		location ~ \.m3u8$ {
			rewrite ^/(.*)$ /$1? break;
			proxy_pass http://localhost:1935;
			proxy_cache livecache;
			proxy_cache_key $scheme$proxy_host$uri;
			proxy_cache_lock on;
			proxy_cache_min_uses 1;
			proxy_cache_use_stale updating;
			proxy_cache_valid 200 1s;
		}
		location ~ \.ts$ {
			rewrite ^/(.*)$ /$1? break;
			proxy_pass http://localhost:1935;
			proxy_cache livecache;
			proxy_cache_key $scheme$proxy_host$uri;
			proxy_cache_lock on;
			proxy_cache_min_uses 1;
			proxy_cache_valid 200 10s;
		}
		# only urls to ts and m3u8 files are allowed, discard any requested path for other urls
		rewrite ^/(.*)$ /? break;
		proxy_pass http://localhost:1935/;
	}
}
