An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix: reload caddy issue
Andras Bacsaib576014d07e5
diff --git a/app/Livewire/Server/Proxy.php b/app/Livewire/Server/Proxy.phpindex 1e23605ff2..4ccbf7d64b 100644--- a/app/Livewire/Server/Proxy.php+++ b/app/Livewire/Server/Proxy.php@@ -54,8 +54,7 @@ class Proxy extends ComponentSaveConfiguration::run($this->server, $this->proxy_settings);$this->server->proxy->redirect_url = $this->redirect_url;$this->server->save();-- setup_default_redirect_404(redirect_url: $this->server->proxy->redirect_url, server: $this->server);+ $this->server->setupDefault404Redirect();$this->dispatch('success', 'Proxy configuration saved.');} catch (\Throwable $e) {return handleError($e, $this);@@ -66,6 +65,9 @@ class Proxy extends Component{try {$this->proxy_settings = CheckConfiguration::run($this->server, true);+ SaveConfiguration::run($this->server, $this->proxy_settings);+ $this->server->save();+ $this->dispatch('success', 'Proxy configuration saved.');} catch (\Throwable $e) {return handleError($e, $this);}diff --git a/app/Models/Server.php b/app/Models/Server.phpindex 098b199317..f067523df7 100644--- a/app/Models/Server.php+++ b/app/Models/Server.php@@ -120,6 +120,106 @@ class Server extends BaseModel}}}+ public function setupDefault404Redirect()+ {+ $dynamic_conf_path = $this->proxyPath() . "/dynamic";+ $proxy_type = $this->proxyType();+ $redirect_url = $this->proxy->redirect_url;++ if ($proxy_type === 'TRAEFIK_V2') {+ $default_redirect_file = "$dynamic_conf_path/default_redirect_404.yaml";+ } else if ($proxy_type === 'CADDY') {+ $default_redirect_file = "$dynamic_conf_path/default_redirect_404.caddy";+ }+ if (empty($redirect_url)) {+ instant_remote_process([+ "mkdir -p $dynamic_conf_path",+ "rm -f $default_redirect_file",+ ], $this);+ return;+ }+ if ($proxy_type === 'TRAEFIK_V2') {+ $dynamic_conf = [+ 'http' =>+ [+ 'routers' =>+ [+ 'catchall' =>+ [+ 'entryPoints' => [+ 0 => 'http',+ 1 => 'https',+ ],+ 'service' => 'noop',+ 'rule' => "HostRegexp(`{catchall:.*}`)",+ 'priority' => 1,+ 'middlewares' => [+ 0 => 'redirect-regexp@file',+ ],+ ],+ ],+ 'services' =>+ [+ 'noop' =>+ [+ 'loadBalancer' =>+ [+ 'servers' =>+ [+ 0 =>+ [+ 'url' => '',+ ],+ ],+ ],+ ],+ ],+ 'middlewares' =>+ [+ 'redirect-regexp' =>+ [+ 'redirectRegex' =>+ [+ 'regex' => '(.*)',+ 'replacement' => $redirect_url,+ 'permanent' => false,+ ],+ ],+ ],+ ],+ ];+ $conf = Yaml::dump($dynamic_conf, 12, 2);+ $conf =+ "# This file is automatically generated by Coolify.\n" .+ "# Do not edit it manually (only if you know what are you doing).\n\n" .+ $conf;++ $base64 = base64_encode($conf);+ } else if ($proxy_type === 'CADDY') {+ $conf = ":80, :443 {+ redir $redirect_url+}";+ray($conf);+ $conf =+ "# This file is automatically generated by Coolify.\n" .+ "# Do not edit it manually (only if you know what are you doing).\n\n" .+ $conf;+ $base64 = base64_encode($conf);+ }+++ instant_remote_process([+ "mkdir -p $dynamic_conf_path",+ "echo '$base64' | base64 -d > $default_redirect_file",+ ], $this);++ if (config('app.env') == 'local') {+ ray($conf);+ }+ if ($proxy_type === 'CADDY') {+ $this->reloadCaddy();+ }+ }public function setupDynamicProxyConfiguration(){$settings = InstanceSettings::get();@@ -250,8 +350,7 @@ class Server extends BaseModelinstant_remote_process(["rm -f $file",], $this);- // $this->reloadCaddy();-+ $this->reloadCaddy();} else {$url = Url::fromString($settings->fqdn);$host = $url->getHost();@@ -264,14 +363,15 @@ $schema://$host {instant_remote_process(["echo '$base64' | base64 -d > $file",], $this);- // $this->reloadCaddy();+ $this->reloadCaddy();}}}}- public function reloadCaddy() {+ public function reloadCaddy()+ {return instant_remote_process([- "docker exec coolify-proxy caddy reload --config /dynamic/Caddyfile",+ "docker exec coolify-proxy caddy reload --config /config/caddy/Caddyfile.autosave",], $this);}public function proxyPath()diff --git a/bootstrap/helpers/proxy.php b/bootstrap/helpers/proxy.phpindex 2bdffaf63c..1eea1893e3 100644--- a/bootstrap/helpers/proxy.php+++ b/bootstrap/helpers/proxy.php@@ -218,80 +218,3 @@ function generate_default_proxy_configuration(Server $server)SaveConfiguration::run($server, $config);return $config;}--function setup_default_redirect_404(string|null $redirect_url, Server $server)-{- $traefik_dynamic_conf_path = $server->proxyPath() . "/dynamic";- $traefik_default_redirect_file = "$traefik_dynamic_conf_path/default_redirect_404.yaml";- if (empty($redirect_url)) {- instant_remote_process([- "mkdir -p $traefik_dynamic_conf_path",- "rm -f $traefik_default_redirect_file",- ], $server);- } else {- $traefik_dynamic_conf = [- 'http' =>- [- 'routers' =>- [- 'catchall' =>- [- 'entryPoints' => [- 0 => 'http',- 1 => 'https',- ],- 'service' => 'noop',- 'rule' => "HostRegexp(`{catchall:.*}`)",- 'priority' => 1,- 'middlewares' => [- 0 => 'redirect-regexp@file',- ],- ],- ],- 'services' =>- [- 'noop' =>- [- 'loadBalancer' =>- [- 'servers' =>- [- 0 =>- [- 'url' => '',- ],- ],- ],- ],- ],- 'middlewares' =>- [- 'redirect-regexp' =>- [- 'redirectRegex' =>- [- 'regex' => '(.*)',- 'replacement' => $redirect_url,- 'permanent' => false,- ],- ],- ],- ],- ];- $yaml = Yaml::dump($traefik_dynamic_conf, 12, 2);- $yaml =- "# This file is automatically generated by Coolify.\n" .- "# Do not edit it manually (only if you know what are you doing).\n\n" .- $yaml;-- $base64 = base64_encode($yaml);- instant_remote_process([- "mkdir -p $traefik_dynamic_conf_path",- "echo '$base64' | base64 -d > $traefik_default_redirect_file",- ], $server);-- if (config('app.env') == 'local') {- ray($yaml);- }- }-}diff --git a/resources/views/livewire/server/proxy.blade.php b/resources/views/livewire/server/proxy.blade.phpindex ba3909739e..60828ec3d5 100644--- a/resources/views/livewire/server/proxy.blade.php+++ b/resources/views/livewire/server/proxy.blade.php@@ -13,7 +13,8 @@<x-forms.button type="submit">Save</x-forms.button></div>- <div class="pb-4 ">Before switching proxies, please read <a href="https://coolify.io/docs/server/switching-proxies">this</a>.</div>+ <div class="pb-4 ">Before switching proxies, please read <a+ href="https://coolify.io/docs/server/switching-proxies">this</a>.</div>@if ($server->proxyType() === 'TRAEFIK_V2')<div class="pb-4">Traefik v2</div>@elseif ($server->proxyType() === 'CADDY')@@ -26,11 +27,8 @@configurations.</div>@endif- @if ($server->proxyType() === 'TRAEFIK_V2')- <x-forms.input placeholder="https://app.coolify.io" id="redirect_url"- label="Default Redirect 404"- helper="All urls that has no service available will be redirected to this domain." />- @endif+ <x-forms.input placeholder="https://app.coolify.io" id="redirect_url" label="Default Redirect 404"+ helper="All urls that has no service available will be redirected to this domain." /><div wire:loading wire:target="loadProxyConfiguration" class="pt-4"><x-loading text="Loading proxy configuration..." /></div>