1. The problem I’m having:
I have multiple subdomains in caddyfile but I want to add basic_auth just to one utm-builder-dev.repina.eu
. I tried multiple ways where to put basic_auth but I can’t get it to work just for one specific domain. The Authentication does not get served when visiting the page.
So far I only managed to get it to work on all subdomains by placing the basic_auth block inside *.repina.eu. But that’s not what I want.
I just switched to using caddy, so would appreciate any pointers. There is no example for subdomains in the documentation.
Thank you!
2. Error messages and/or full log output:
no errors
3. Caddy version:
2.9.1
4. How I installed and ran Caddy:
a. System environment:
Installed in LXC on proxmox.
b. Command:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
c. Service/unit/compose file:
PASTE OVER THIS, BETWEEN THE ``` LINES.
Please use the preview pane to ensure it looks nice.
d. My complete Caddy config:
utm-builder-dev.repina.eu {
tls /etc/caddy/certs/repina_eu-origin-cert.pem /etc/caddy/certs/repina_eu-private-key.key
basic_auth {
juronja pass
}
reverse_proxy 192.168.84.16:3131
header -Server
header {
# This tells the client to store responses for one week.
Cache-Control max-age=604800
# Set the referrer policy to send the origin only when making cross-origin requests.
Referrer-Policy origin-when-cross-origin
# Enable HSTS (HTTP Strict Transport Security) to force HTTPS for one year including subdomains.
Strict-Transport-Security max-age=31536000 includeSubDomains
# Prevent the site from being embedded in an iframe, mitigating clickjacking.
X-Frame-Options DENY
# Prevent MIME type sniffing, mitigating certain security vulnerabilities.
X-Content-Type-Options nosniff
# This will deny website access to the listed hardware features for security purposes.
Permissions-Policy autoplay=(), camera=(), microphone=(), midi=(), usb=()
# Block XSS attacks to some degree using a report-only CSP.
Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' cdn.jsdelivr.net fonts.googleapis.com 'unsafe-inline'; img-src 'self' data:; font-src 'self' cdn.jsdelivr.net fonts.gstatic.com; connect-src 'self'; frame-ancestors 'none'; upgrade-insecure-requests;"
}
request_body {
max_size 100KB
}
rate_limit {
# distributed # only needed if multiple caddy instances
zone limit_by_ip {
key {remote_host}
events 20
window 10s
}
}
}
*.repina.eu {
tls /etc/caddy/certs/repina_eu-origin-cert.pem /etc/caddy/certs/repina_eu-private-key.key
header -Server
header {
# This tells the client to store responses for one week.
Cache-Control max-age=604800
# Set the referrer policy to send the origin only when making cross-origin requests.
Referrer-Policy origin-when-cross-origin
# Enable HSTS (HTTP Strict Transport Security) to force HTTPS for one year including subdomains.
Strict-Transport-Security max-age=31536000 includeSubDomains
}
@ha host ha.repina.eu
handle @ha {
reverse_proxy 192.168.3.2:8123
header {
# This will deny website access to the listed hardware features for security purposes.
Permissions-Policy autoplay=(), midi=()
# Block XSS attacks to some degree using a report-only CSP.
Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: basemaps.cartocdn.com brands.home-assistant.io; font-src 'self'; connect-src 'self' raw.githubusercontent.com; upgrade-insecure-requests;"
}
rate_limit /auth/authorize* {
# distributed # only needed if multiple caddy instances
zone limit_by_ip {
key {remote_host}
events 20
window 10s
}
}
}
@dilute host dilute.repina.eu
handle @dilute {
reverse_proxy 192.168.84.15:7474
header {
# Prevent the site from being embedded in an iframe, mitigating clickjacking.
X-Frame-Options DENY
# Prevent MIME type sniffing, mitigating certain security vulnerabilities.
X-Content-Type-Options nosniff
# This will deny website access to the listed hardware features for security purposes.
Permissions-Policy autoplay=(), camera=(), microphone=(), midi=(), usb=()
# Block XSS attacks to some degree using a report-only CSP.
Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' cdn.jsdelivr.net 'unsafe-inline'; img-src 'self' data:; font-src 'self' cdn.jsdelivr.net; connect-src 'self'; frame-ancestors 'none'; upgrade-insecure-requests;"
}
request_body {
max_size 100KB
}
rate_limit {
# distributed # only needed if multiple caddy instances
zone limit_by_ip {
key {remote_host}
events 10
window 5s
}
}
}
# @utm-dev host utm-builder-dev.repina.eu
# handle @utm-dev {
# reverse_proxy 192.168.84.16:3131
# header {
# # Prevent the site from being embedded in an iframe, mitigating clickjacking.
# X-Frame-Options DENY
# # Prevent MIME type sniffing, mitigating certain security vulnerabilities.
# X-Content-Type-Options nosniff
# # This will deny website access to the listed hardware features for security purposes.
# Permissions-Policy autoplay=(), camera=(), microphone=(), midi=(), usb=()
# # Block XSS attacks to some degree using a report-only CSP.
# Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' cdn.jsdelivr.net fonts.googleapis.com 'unsafe-inline'; img-src 'self' data:; font-src 'self' cdn.jsdelivr.net fonts.gstatic.com; connect-src 'self'; frame-ancestors 'none'; upgrade-insecure-requests;"
# }
# request_body {
# max_size 100KB
# }
# rate_limit {
# # distributed # only needed if multiple caddy instances
# zone limit_by_ip {
# key {remote_host}
# events 20
# window 10s
# }
# }
# basic_auth {
# juronja pass
# }
# }
}