error_page 497 301 =307 https://$host:$server_port$request_uri;

location /robots.txt {
	return 200 "User-agent: *\nDisallow: /\n";
}

location /sitemap.xml {
	return 200 "User-agent: *\nDisallow: /\n";
}

location /maintenance.html {
	internal;
}

location /wss {
	proxy_pass_request_headers      on;
	proxy_cache        off;
	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection $connection_upgrade;
	proxy_set_header    Host               $host;
	proxy_set_header    X-Real-IP          $remote_addr;
	proxy_set_header    X-Forwarded-For    $remote_addr;
	proxy_set_header    X-Forwarded-Host   $host;
	proxy_set_header    X-Forwarded-Server $host;
	proxy_set_header    X-Forwarded-Port   $server_port;
	proxy_set_header    X-Forwarded-Proto  $scheme;
	add_header          Cache-Control 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';
	add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
	add_header Pragma 'no-cache';
	add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range' always;
	expires 0;
	proxy_pass http://websocket;
}

location / {
	autoindex on;

	if ($request_method = 'OPTIONS') {
		add_header 'Access-Control-Allow-Origin' '*';
		add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
		add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range';
		add_header 'Content-Type' 'text/plain; charset=utf-8';
		add_header 'Content-Length' 0;
		return 204;
	}
	if ($request_method = 'GET') {
		add_header 'Access-Control-Allow-Origin' '*' always;
		add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always;
		add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,Content-Type,Range' always;
		add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
	}

	if (!-f $document_root/connection/ready) {
		return 503;
	}

	expires 0;
}
