{
	servers {
		listener_wrappers {
			proxy_protocol
			tls
		}

		# Only trust PROXY protocol from local forwarder.
		trusted_proxies static 127.0.0.1/32 ::1/128
	}

	http_port 8080
	https_port 8443
}

fromchat.ru {
	reverse_proxy frontend:8301 {
		header_up X-Real-IP {remote_host}
	}

	# Security headers
	header {
		X-XSS-Protection "1; mode=block" # Prevent XSS attacks
		X-Content-Type-Options "nosniff" # Prevent MIME type sniffing
		X-Frame-Options "DENY" # Prevent clickjacking
		Referrer-Policy "strict-origin-when-cross-origin"
		Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https: blob:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'none';"
		Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
		Permissions-Policy "geolocation=(), microphone=(self), camera=(self)"
	}

	rate_limit {
		zone global {
			key {remote_ip}
			window 1m
			burst 20
			events 500
		}
	}

	handle_errors {
		@errors {
			expression {err.status_code} >= 400
		}

		handle @errors {
			rewrite * /{err.status_code}
			reverse_proxy https://http.cat {
				header_up Host {upstream_hostport}
				replace_status {err.status_code}
			}
		}
	}
}

beta.fromchat.ru {
    reverse_proxy 95.165.0.162:8301 {
        header_up X-Real-IP {remote_host}
    }

	# Security headers
	header {
		X-XSS-Protection "1; mode=block" # Prevent XSS attacks
		X-Content-Type-Options "nosniff" # Prevent MIME type sniffing
		X-Frame-Options "DENY" # Prevent clickjacking
		Referrer-Policy "strict-origin-when-cross-origin"
		Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https: blob:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'none';"
		Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
		Permissions-Policy "geolocation=(), microphone=(self), camera=(self)"
	}

	rate_limit {
		zone global {
			key {remote_ip}
			window 1m
			burst 20
			events 1000
		}
	}

	handle_errors {
		@errors {
			expression {err.status_code} >= 400
		}

		handle @errors {
			rewrite * /{err.status_code}
			reverse_proxy https://http.cat {
				header_up Host {upstream_hostport}
				replace_status {err.status_code}
			}
		}
	}
}

git.fromchat.ru {
	reverse_proxy 172.18.0.1:3000 host.docker.internal:3000 172.17.0.1:3000 {
		lb_policy first
        header_up X-Real-IP {remote_host}
	}

	# Security headers
	header {
		X-XSS-Protection "1; mode=block" # Prevent XSS attacks
		X-Content-Type-Options "nosniff" # Prevent MIME type sniffing
		X-Frame-Options "DENY" # Prevent clickjacking
		Referrer-Policy "strict-origin-when-cross-origin"
		Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
		Permissions-Policy "geolocation=(), microphone=(), camera=()"
	}

	rate_limit {
		zone global {
			key {remote_ip}
			window 1m
			burst 20
			events 500
		}
	}
}