1. Caddy version (caddy version
):
newest
2. How I run Caddy:
VPS
a. System environment:
Ubuntu 20.4 LTS
b. Command:
Paste command here.
c. Service/unit/compose file:
Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.
d. My complete Caddyfile or JSON config:
# GLOBAL
{
# Global options block. Entirely optional, https is on by default
# Optional email key for lets encrypt
# Optional staging lets encrypt for testing.
# acme_ca https://acme-staging-v02.api.letsencrypt.org/directory
servers {
timeouts {
read_body 10s
read_header 10s
write 10s
idle 2m
}
max_header_size 16384
}
}
# SNIPPETS
(mustheaders) {
header {
Strict-Transport-Security "max-age=31536000; includesubdomains; preload"
X-Content-Type-Options "nosniff"
X-Frame-Options "SAMEORIGIN"
Referrer-Policy "same-origin"
X-Xss-Protection "1; mode=block"
Feature-Policy "accelerometer 'none'; autoplay 'none'; camera 'none'; encrypted-media 'none'; fullscreen 'self'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; midi 'none'; payment 'none'; picture-in-picture *; sync-xhr 'none'; usb 'none'"
Expect-CT "max-age=604800"
-Server
}
}
(onlinewebsite) {
@offline expression `"{args.0}" == "no"`
handle @offline {
header X-Robots-Tag "noindex, nofollow, noarchive, nosnippet, notranslate, noimageindex"
header Cache-Control "no-cache, no-store, must-revalidate"
@public_networks not remote_ip 11.111.11.11 #EXAMPLE MY IP
rewrite @public_networks index.html
root * /home/maintenance.site
file_server
}
header X-Robots-Tag "noarchive, notranslate"
}
(compression) {
encode zstd gzip
}
(caching) {
@static {
file
path *.css *.js *.ico *.gif *.jpg *.jpeg *.png *.svg *.woff
}
handle @static {
header ?Cache-Control "public, max-age=5184000, must-revalidate"
}
handle {
header ?Cache-Control "no-cache, no-store, must-revalidate"
}
}
(robots) {
header /robots.txt {
User-agent:*
Allow: /
User-agent: *
Disallow: /*.php$
Disallow: /*.inc$
Disallow: /*.zip$
Disallow: /*.pdf$
Sitemap: https://{http.request.host.labels.1}.{http.request.host.labels.0}/sitemap.xml
}
respond /robots.txt 200
}
(proxy) {
header_up X-Forwarded-For {remote}
header_up X-Real-IP {remote}
header_down X-Powered-By "the Holy Spirit"
header_down Server "CERN httpd"
}
(logs) {
log {
output file /var/log/caddy/caddy.log
}
}
(php) {
php_fastcgi / unix//run/php/php7.4-fpm.sock
}
# WEBSITES
website.com {
import mustheaders
import caching
import onlinewebsite yes
respond /healthcheck 200
reverse_proxy 127.0.0.1:2050 {
import proxy
}
import logs
}
3. The problem I’m having:
Please check the “onlinewebsite” snippet. I use it to make my website offline for maintenance. I wanted to redirect users to maintenance page except me. However “not remote_ip” doesn’t work and I also see the maintenance page.
How to exclude myself from the maintenance rewrite?
4. Error messages and/or full log output:
no errors
5. What I already tried:
no clue what to do next