Add load balancer (#453)

This commit is contained in:
Saeed Vaziry
2025-01-30 23:52:51 +01:00
committed by GitHub
parent 53e20cbc2a
commit 6966f06b1a
54 changed files with 3128 additions and 1833 deletions

View File

@ -6,6 +6,27 @@
}
@endif
@if ($site->type === \App\Enums\SiteType::LOAD_BALANCER)
upstream backend {
@switch($site->type_data['method'] ?? \App\Enums\LoadBalancerMethod::ROUND_ROBIN)
@case(\App\Enums\LoadBalancerMethod::LEAST_CONNECTIONS)
least_conn;
@break
@case(\App\Enums\LoadBalancerMethod::IP_HASH)
ip_hash;
@break
@default
@endswitch
@if ($site->loadBalancerServers()->count() > 0)
@foreach($site->loadBalancerServers as $server)
server {{ $server->ip }}:{{ $server->port }} {{ $server->backup ? 'backup' : '' }} {{ $server->weight ? 'weight='.$server->weight : '' }};
@endforeach
@else
server 127.0.0.1;
@endif
}
@endif
server {
@if (!$site->activeSsl || !$site->force_ssl)
listen 80;
@ -26,18 +47,7 @@
charset utf-8;
@if ($site->port)
location / {
try_files $uri $uri/ /index.html;
}
location / {
proxy_pass http://127.0.0.1:{{ $site->port }}/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $remote_addr;
}
@elseif ($site->php_version)
@if ($site->type()->language() === 'php')
@php
$phpSocket = 'unix:/var/run/php/php-fpm.sock';
if ($site->isIsolated()) {
@ -55,6 +65,16 @@
}
@endif
@if ($site->type === \App\Enums\SiteType::LOAD_BALANCER)
location / {
proxy_pass http://backend$request_uri;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
@endif
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }