切換選單
切換偏好設定選單
切換個人選單
尚未登入
若您做出任何編輯,會公開您的 IP 位址。

Caddy

出自H.-H.'s Wiki
於 2025年12月26日 (五) 16:14 由 Hsins留言 | 貢獻 所作的修訂 (建立內容為「== 安裝 == <syntaxhighlight lang="aspectj"> # Install from Official Repository $ apt install -y debian-keyring debian-archive-keyring apt-transport-https curl $ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg $ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list $ chmod o+r /usr/share/keyrings/caddy-…」的新頁面)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)

安裝

# Install from Official Repository
$ apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
$ curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
$ chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg
$ chmod o+r /etc/apt/sources.list.d/caddy-stable.list
$ apt update
$ apt install caddy

# Replace with compiled version
$ xcaddy build --with [...]

$ systemctl stop caddy
$ cp /usr/bin/caddy /usr/bin/caddy.bak
$ cp ~/caddy /usr/bin/caddy
$ chmod 755 /usr/bin/caddy
$ setcap cap_net_bind_service=+ep /usr/bin/caddy
$ apt-mark hold caddy

使用 Caddy 搭配 GeoIP 限制地區

demo.example.com {
    @taiwan {
        maxmind_geolocation {
            db_path "/etc/caddy/GeoLite2-Country.mmdb"
            allow_countries TW
        }
    }
    
    handle @taiwan {
        reverse_proxy https://demo.example.com {
            header_up Host demo.example.com
            header_up X-Real-IP {remote_host}
        }
    }
    
    handle {
        respond "Access Denied" 403
    }
}