fix: reload caddy issue
This commit is contained in:
@@ -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 BaseModel
|
||||
instant_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()
|
||||
|
||||
Reference in New Issue
Block a user