Skip to content

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.

Merge branch 'next' into feat/disable-default-redirect

Kael9a1b6449c8c2
diff --cc app/Models/Server.php
index f45905cb85,9e947c20bd..de13a9c310
--- a/app/Models/Server.php
+++ b/app/Models/Server.php
@@@ -174,62 -164,68 +172,62 @@@ class Server extends BaseMode
return $this->proxyType() && $this->proxyType() !== 'NONE' && $this->isFunctional() && ! $this->isSwarmWorker() && ! $this->settings->is_build_server;
}
- public function setupDefault404Redirect()
+ public function setupDefaultRedirect()
{
- $dynamic_conf_path = $this->proxyPath().'/dynamic';
+ $banner =
- "# This file is generated by Coolify, do not edit it manually.\n" .
++ "# This file is generated by Coolify, do not edit it manually.\n".
+ "# Disable the default redirect to customize (only if you know what are you doing).\n\n";
+ $dynamic_conf_path = $this->proxyPath() . '/dynamic';
$proxy_type = $this->proxyType();
+ $redirect_enabled = $this->proxy->redirect_enabled ?? true;
$redirect_url = $this->proxy->redirect_url;
+
if ($proxy_type === ProxyTypes::TRAEFIK->value) {
- $default_redirect_file = "$dynamic_conf_path/default_redirect_404.yaml";
+ $default_redirect_file = "$dynamic_conf_path/default_redirect_503.yaml";
} elseif ($proxy_type === ProxyTypes::CADDY->value) {
- $default_redirect_file = "$dynamic_conf_path/default_redirect_404.caddy";
+ $default_redirect_file = "$dynamic_conf_path/default_redirect_503.caddy";
}
- if (empty($redirect_url)) {
- if ($proxy_type === ProxyTypes::CADDY->value) {
- $conf = ':80, :443 {
-respond 404
-}';
- $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 | tee $default_redirect_file > /dev/null",
- ], $this);
- $this->reloadCaddy();
- return;
- }
- instant_remote_process([
- "mkdir -p $dynamic_conf_path",
- "rm -f $default_redirect_file",
- ], $this);
+ instant_remote_process([
+ "mkdir -p $dynamic_conf_path",
+ "rm -f $dynamic_conf_path/default_redirect_404.yaml",
+ "rm -f $dynamic_conf_path/default_redirect_404.caddy",
+ ], $this);
- return;
- }
- if ($proxy_type === ProxyTypes::TRAEFIK->value) {
- $dynamic_conf = [
- 'http' => [
- 'routers' => [
- 'catchall' => [
- 'entryPoints' => [
- 0 => 'http',
- 1 => 'https',
- ],
- 'service' => 'noop',
- 'rule' => 'HostRegexp(`.+`)',
- 'tls' => [
- 'certResolver' => 'letsencrypt',
- ],
- 'priority' => 1,
- 'middlewares' => [
- 0 => 'redirect-regexp',
+ if (!$redirect_enabled) {
+ instant_remote_process(["rm -f $default_redirect_file"], $this);
+ } else {
+ if ($proxy_type === ProxyTypes::CADDY->value) {
+ if (empty($redirect_url)) {
+ $conf = ':80, :443 {
+ respond 503
+}';
+ } else {
+ $conf = ":80, :443 {
+ redir $redirect_url
+}";
+ }
+ } elseif ($proxy_type === ProxyTypes::TRAEFIK->value) {
+ $dynamic_conf = [
+ 'http' => [
+ 'routers' => [
+ 'catchall' => [
+ 'entryPoints' => [
+ 0 => 'http',
+ 1 => 'https',
+ ],
+ 'service' => 'noop',
+ 'rule' => 'HostRegexp(`.+`)',
+ 'tls' => [
+ 'certResolver' => 'letsencrypt',
+ ],
+ 'priority' => 1,
],
],
- ],
- 'services' => [
- 'noop' => [
- 'loadBalancer' => [
- 'servers' => [
- 0 => [
- 'url' => '',
- ],
+ 'services' => [
+ 'noop' => [
+ 'loadBalancer' => [
+ 'servers' => [],
],
],
],
@@@ -250,17 -238,32 +248,17 @@@
'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);
- } elseif ($proxy_type === ProxyTypes::CADDY->value) {
- $conf = ":80, :443 {
- redir $redirect_url
-}";
- $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;
+ ];
+ }
+ $conf = Yaml::dump($dynamic_conf, 12, 2);
+ }
- $conf = $banner . $conf;
++ $conf = $banner.$conf;
$base64 = base64_encode($conf);
+ instant_remote_process([
+ "echo '$base64' | base64 -d | tee $default_redirect_file > /dev/null",
+ ], $this);
}
- instant_remote_process([
- "mkdir -p $dynamic_conf_path",
- "echo '$base64' | base64 -d | tee $default_redirect_file > /dev/null",
- ], $this);
-
if ($proxy_type === 'CADDY') {
$this->reloadCaddy();
}