absolute_redirect off;

index index.html;

auth_request /auth_check;

location = /auth_check {
	internal;
	proxy_pass http://kvmd/auth/check;
	proxy_pass_request_body off;
	proxy_set_header Content-Length "";
	auth_request off;
}

location / {
	root /usr/share/kvmd/web;
	include /etc/kvmd/nginx/loc-login.conf;
	include /etc/kvmd/nginx/loc-nocache.conf;
}

location @login {
	return 302 /login;
}

location /login {
	root /usr/share/kvmd/web;
	auth_request off;
}

location /share {
	root /usr/share/kvmd/web;
	include /etc/kvmd/nginx/loc-nocache.conf;
	auth_request off;
}

location = /share/css/user.css {
	alias /etc/kvmd/web.css;
	auth_request off;
}

location = /favicon.ico {
	alias /usr/share/kvmd/web/favicon.ico;
	include /etc/kvmd/nginx/loc-nocache.conf;
	auth_request off;
}

location = /robots.txt {
	alias /usr/share/kvmd/web/robots.txt;
	include /etc/kvmd/nginx/loc-nocache.conf;
	auth_request off;
}

location /api/ws {
	rewrite ^/api/ws$ /ws break;
	rewrite ^/api/ws\?(.*)$ /ws?$1 break;
	proxy_pass http://kvmd;
	include /etc/kvmd/nginx/loc-proxy.conf;
	include /etc/kvmd/nginx/loc-websocket.conf;
	auth_request off;
}

location /api/msd/write_remote {
	rewrite ^/api/msd/write_remote$ /msd/write_remote break;
	rewrite ^/api/msd/write_remote\?(.*)$ /msd/write_remote?$1 break;
	proxy_pass http://kvmd;
	include /etc/kvmd/nginx/loc-proxy.conf;
	proxy_read_timeout 7d;
	postpone_output 0;
	proxy_buffering off;
	proxy_ignore_headers X-Accel-Buffering;
	auth_request off;
}

location /api/msd/write {
	rewrite ^/api/msd/write$ /msd/write break;
	rewrite ^/api/msd/write\?(.*)$ /msd/write?$1 break;
	proxy_pass http://kvmd;
	include /etc/kvmd/nginx/loc-proxy.conf;
	limit_rate 6250k;
	limit_rate_after 50k;
	client_max_body_size 0;
	proxy_request_buffering off;
	auth_request off;
}

location /api/log {
	rewrite ^/api/log$ /log break;
	rewrite ^/api/log\?(.*)$ /log?$1 break;
	proxy_pass http://kvmd;
	include /etc/kvmd/nginx/loc-proxy.conf;
	proxy_read_timeout 7d;
	postpone_output 0;
	proxy_buffering off;
	proxy_ignore_headers X-Accel-Buffering;
	auth_request off;
}

location /api {
	rewrite ^/api$ / break;
	rewrite ^/api/(.*)$ /$1 break;
	proxy_pass http://kvmd;
	include /etc/kvmd/nginx/loc-proxy.conf;
	auth_request off;
}

location /streamer {
	rewrite ^/streamer$ / break;
	rewrite ^/streamer\?(.*)$ ?$1 break;
	rewrite ^/streamer/(.*)$ /$1 break;
	proxy_pass http://ustreamer;
	include /etc/kvmd/nginx/loc-proxy.conf;
	postpone_output 0;
	proxy_buffering off;
	proxy_ignore_headers X-Accel-Buffering;
}

location /redfish {
	proxy_pass http://kvmd;
	include /etc/kvmd/nginx/loc-proxy.conf;
	auth_request off;
}
