docker-compose-configs/invidious/invidious-vpn/haproxy/haproxy.cfg
2024-09-14 20:29:49 -03:00

96 lines
2.9 KiB
INI

global
# This because haproxy is dumb and likes to use the maxconnection from the kernel and that is super mega huge making haproxy oom
maxconn 16384
# 777 perms for all sockets
unix-bind mode 777
stats socket ipv4@0.0.0.0:8405 level admin
resolvers docker
# To be able to use multiple replicas of invidious
# using domains
nameserver dns1 127.0.0.11:53
defaults
mode http
timeout client 10s
timeout connect 10s
timeout server 30s
timeout http-request 10s
# Prometheus for graphs
frontend prometheus
bind *:8404
mode http
http-request use-service prometheus-exporter if { path /metrics }
no log
frontend stats
mode http
bind *:8405
stats enable
stats uri /stats
stats refresh 1s
stats admin if TRUE
cache invidious-thumbnail-cache
# 96MB
total-max-size 96
# 32kB
max-object-size 32768
# 30min
max-age 1800
process-vary on
cache invidious-ggpht-cache
# 96MB
total-max-size 96
# 32kB
max-object-size 32768
# 1h
max-age 3600
process-vary on
frontend invidious
bind *:8001
default_backend invidious
frontend http3-proxy
http-request set-var(txn.vipath) path
bind *:8004
default_backend http3-proxy
backend invidious
balance leastconn
server invidious-1-vpn gluetun:3000 check init-addr libc,none
server invidious-2-vpn gluetun:3001 check init-addr libc,none
server invidious-3-vpn gluetun:3002 check init-addr libc,none
server invidious-4-vpn gluetun:3003 check init-addr libc,none
server invidious-5-vpn gluetun:3004 check init-addr libc,none
server invidious-6-vpn gluetun:3005 check init-addr libc,none
# https://www.haproxy.com/documentation/haproxy-configuration-tutorials/service-reliability/retries/
option redispatch 2
backend http3-proxy
timeout server 15s
# Caches video thumbnails, profile pictures and others
http-request cache-use invidious-thumbnail-cache if { path_beg /vi/ }
http-response cache-store invidious-thumbnail-cache
http-request cache-use invidious-ggpht-cache if { path_beg /ggpht/ }
http-response cache-store invidious-ggpht-cache
# https://discourse.haproxy.org/t/http-response-set-header-with-condition-not-working/3108
acl youtube_thumbnails var(txn.path) -m beg /vi/
acl youtube_ggpht var(txn.path) -m beg /ggpht/
http-response set-header X-Cache-Status HIT if !{ srv_id -m found } youtube_thumbnails
http-response set-header X-Cache-Status MISS if { srv_id -m found } youtube_thumbnails
http-response set-header X-Cache-Status HIT if !{ srv_id -m found } youtube_ggpht
http-response set-header X-Cache-Status MISS if { srv_id -m found } youtube_ggpht
server http3-proxy-1-vpn gluetun:8080 check init-addr libc,none
# https://www.haproxy.com/documentation/haproxy-configuration-tutorials/service-reliability/retries/
# Use another server if one takes too long to reply
# option redispatch 2
# Only 1 server, not neccessary