diff --git a/.editorconfig b/.editorconfig index ec07101..f483581 100644 --- a/.editorconfig +++ b/.editorconfig @@ -16,3 +16,12 @@ tab_width = 2 [*.md] trim_trailing_whitespace = false + +[Caddyfile] +indent_style = tab +indent_size = 4 +tab_width = 4 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/proxy/caddy/Caddyfile b/proxy/caddy/Caddyfile index a3b4aaa..4cc073c 100644 --- a/proxy/caddy/Caddyfile +++ b/proxy/caddy/Caddyfile @@ -1,91 +1,113 @@ { -# acme_ca https://acme-v02.api.letsencrypt.org/directory - email {env.EMAIL} - log { - format console - } + email {env.EMAIL} + log default { + output stdout + format console + } +} + +(error) { + root * /usr/share/caddy + rewrite * /error.html + templates + file_server { + status {err.status_code} + } } *.{$DOMAIN} { - tls { - dns netcup { - customer_number {env.NETCUP_CUSTOMER_NUMBER} - api_key {env.NETCUP_API_KEY} - api_password {env.NETCUP_API_PASSWORD} - } - propagation_timeout 900s - propagation_delay 600s - resolvers 46.38.225.230 46.38.252.230 - } - header Strict-Transport-Security "max-age=63072000" + tls { + dns netcup { + customer_number {env.NETCUP_CUSTOMER_NUMBER} + api_key {env.NETCUP_API_KEY} + api_password {env.NETCUP_API_PASSWORD} + } + propagation_timeout 900s + propagation_delay 600s + resolvers 46.38.225.230 46.38.252.230 + } + header Strict-Transport-Security "max-age=63072000" - @git host git.{$DOMAIN} - handle @git { - reverse_proxy forgejo:3000 - } + @git host git.{$DOMAIN} + handle @git { + reverse_proxy forgejo:3000 + } - @news host news.{$DOMAIN} - handle @news { - reverse_proxy miniflux:8080 - } + @news host news.{$DOMAIN} + handle @news { + reverse_proxy miniflux:8080 + } - @nc-push expression `(host('cloud.{$DOMAIN}') && path('/push/*'))` - handle @nc-push { - reverse_proxy push:7867 - } + @nc-push expression `(host('cloud.{$DOMAIN}') && path('/push/*'))` + handle @nc-push { + reverse_proxy push:7867 + } - @nextcloud host cloud.{$DOMAIN} - handle @nextcloud { - reverse_proxy webserver-nextcloud:80 - } + @nextcloud host cloud.{$DOMAIN} + handle @nextcloud { + reverse_proxy webserver-nextcloud:80 + } - @office host office.{$DOMAIN} - handle @office { - reverse_proxy collabora:9980 - } + @office host office.{$DOMAIN} + handle @office { + reverse_proxy collabora:9980 + } - @drawio host drawio.{$DOMAIN} - handle @drawio { - reverse_proxy drawio:8080 - } + @drawio host drawio.{$DOMAIN} + handle @drawio { + reverse_proxy drawio:8080 + } - @whoami host whoami.{$DOMAIN} - handle @whoami { - reverse_proxy whoami:80 - } + @whoami host whoami.{$DOMAIN} + handle @whoami { + reverse_proxy whoami:80 + } - @push host push.{$DOMAIN} - handle @push { - reverse_proxy ntfy:80 - } + @push host push.{$DOMAIN} + handle @push { + reverse_proxy ntfy:80 + } - @wallabag host wallabag.{$DOMAIN} - handle @wallabag { - reverse_proxy wallabag:80 - } + @wallabag host wallabag.{$DOMAIN} + handle @wallabag { + reverse_proxy wallabag:80 + } - @www host www.{$DOMAIN} - handle @www { - reverse_proxy webserver-www:80 - } + @www host www.{$DOMAIN} + handle @www { + file_server { + root /usr/share/caddy + hide .git Readme.md + } + } - @mail host mail.{$DOMAIN} - handle @mail { - reverse_proxy nginx-mailcow:8090 - } + @mail host mail.{$DOMAIN} + handle @mail { + reverse_proxy nginx-mailcow:8090 + } - # Fallback for otherwise unhandled domains - handle { - respond 404 - } + # Fallback for otherwise unhandled domains + handle { + respond "404 Not Found" 404 + } + + # handle wrong url pathes + handle_errors 404 { + #respond "{err.status_code} {err.status_text}" {err.status_code} + import error + } + + # handle errors of proxy backends are down + # handle_errors 502 { + # respond "503 Service Unavailable" 503 + # } + + # every other error + handle_errors { + import error + } } {$DOMAIN} { - redir https://www.{$DOMAIN}{uri} + redir https://www.{$DOMAIN}{uri} } - - - - - - diff --git a/proxy/docker-compose.yaml b/proxy/docker-compose.yaml index f8d347e..1670926 100755 --- a/proxy/docker-compose.yaml +++ b/proxy/docker-compose.yaml @@ -11,9 +11,11 @@ services: - "443:443" - "443:443/udp" volumes: - - $PWD/caddy/Caddyfile:/etc/caddy/Caddyfile - - ${STORAGE_PATH}/caddy/data:/data - - ${STORAGE_PATH}/caddy/config:/config + - $PWD/caddy/Caddyfile:/etc/caddy/Caddyfile + - ${STORAGE_PATH}/caddy/data:/data + - ${STORAGE_PATH}/caddy/config:/config + - ${WWW_PATH}:/usr/share/caddy:ro + environment: - NETCUP_CUSTOMER_NUMBER=${NETCUP_CUSTOMER_NUMBER} - NETCUP_API_KEY=${NETCUP_API_KEY} diff --git a/proxy/reload.sh b/proxy/reload.sh new file mode 100755 index 0000000..27d9320 --- /dev/null +++ b/proxy/reload.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker compose exec -w /etc/caddy caddy caddy reload \ No newline at end of file diff --git a/www/docker-compose.yaml b/www/docker-compose.yaml deleted file mode 100644 index 36be945..0000000 --- a/www/docker-compose.yaml +++ /dev/null @@ -1,21 +0,0 @@ -services: - - webserver-www: - image: nginx:stable - volumes: - - ${HTML}:/usr/share/nginx/html:ro - - $PWD/nginx.conf:/etc/nginx/nginx.conf:ro - networks: - - web - restart: unless-stopped - healthcheck: - test: ["CMD", "curl" ,"--fail", "localhost"] - interval: 5s - timeout: 3s - labels: - - "docker.group=www" - -networks: - web: - external: true - diff --git a/www/nginx.conf b/www/nginx.conf deleted file mode 100644 index 73d1ce1..0000000 --- a/www/nginx.conf +++ /dev/null @@ -1,67 +0,0 @@ -user nginx; -worker_processes auto; - -error_log /var/log/nginx/error.log notice; -pid /var/run/nginx.pid; - - -events { - worker_connections 1024; -} - - -http { - include /etc/nginx/mime.types; - default_type application/octet-stream; - - log_format main '$remote_addr - $remote_user [$time_local] "$request" ' - '$status $body_bytes_sent "$http_referer" ' - '"$http_user_agent" "$http_x_forwarded_for"'; - - access_log /var/log/nginx/access.log main; - - sendfile on; - #tcp_nopush on; - - keepalive_timeout 65; - - #gzip on; - - # include /etc/nginx/conf.d/*.conf; - ############################################ - server { - listen 80; - listen [::]:80; - server_name localhost; - - #access_log /var/log/nginx/host.access.log main; - - location / { - root /usr/share/nginx/html; - index index.html index.htm; - } - - #error_page 404 /404.html; - - # redirect server error pages to the static page /50x.html - # - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } - - # hide .git folder - location ~ /\.git { - deny all; - return 404; - } - - location ~ /Readme.md { - deny all; - return 404; - } - - } - - # include /etc/nginx/conf.d/*.conf; -}