gzip_vary on;
gzip_comp_level 6;
gzip_disable msie6;
gzip_proxied any;
gzip_types text/plain text/css text/javascript application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss;

set_real_ip_from  172.16.0.0/12; # docker
real_ip_header    X-Forwarded-For;
real_ip_recursive on;

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

server {
	listen 80;
	server_name _;
	server_tokens off;

	location / {
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Host $host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection $connection_upgrade;
		proxy_read_timeout 7200s;
		proxy_max_temp_file_size 50000m;
		proxy_pass http://127.0.0.1:34801;
	}

	location ~ ^/(assets|songs|src)/ {
		root   /taiko-web/public;
		location ~ ^/songs/([0-9]+)/preview\.mp3$ {
			expires 30d;
			try_files $uri /api/preview?id=$1;
		}
		location ~ ^/songs/([0-9]+)/main\.(mp3|ogg)$ {
			expires max;
		}
		location ~ ^/songs/([0-9]+)/*\.(tja|osu)$ {
			add_header Cache-Control no-store;
			expires -1;
		}
		location ~ ^/src/ {
			expires 1h;
		}
	}

	location /p2 {
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header Host $host;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection $connection_upgrade;
		proxy_http_version 1.1;
		proxy_pass http://127.0.0.1:34802;
	}
}
