Caddy docker-compose 部署及反代教學

Caddy和我們常用的Nginx、Apache等Web服務器相比,最大的特點就是部署簡單,而且又可以最大限度地節省服務器資源,最顯著的特性是默認啟用 HTTPS,它是日前唯一無需額外配置即可提供 HTTPS 特性的 Web 服務器。

Docker安裝

curl -sSL https://get.docker.com | bash
service docker restart

docker-compose安装

curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

然後我們先來創建個檔案夾並創建docker-compose.yml

mkdir caddy && cd caddy && nano docker-compose.yml

寫入如下內容:

version: "3"

services:
  caddy:
    image: caddy:latest
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./caddy_data:/data
      - ./caddy_config:/config

volumes:
  caddy_data:
  caddy_config:

創建Caddyfile並配置:

nano Caddyfile
你的域名 {
    reverse_proxy 內部ip:要反代的端口
    tls 你的郵箱
}

如果你有更多的端口需要反代,也可以:

你的域名1 {
    reverse_proxy 內部ip:要反代的端口1
    tls 你的郵箱
}

你的域名2 {
    reverse_proxy ip:要反代的端口2
    tls 你的郵箱
}

比如你的服務器同時有ttrss、FileRun、Bitwarden、blog

ttrss.example.com {
    reverse_proxy 127.0.0.1:1234
    tls 你的郵箱
}

FileRun.example.com {
    root www/Filerun
    tls 你的郵箱
}

Bitwarden.example.com {
    reverse_proxy 127.0.0.1:2345
    tls 你的郵箱
}

Blog.example.com {
    root www/wordpress
    tls 你的郵箱
    respond /uploads/*.php 404
    @wp-admin {
    path  not ^\/wp-admin/*
    }
    rewrite @wp-admin {path}/index.php?{query}
    file_server
}

配置好Caddyfile後,啟動容器

docker-compose up -d

19 Comments

  1. ceryainly like yokur web-site hhowever yyou nneed to tdst the spelling
    onn several of your posts. Several oof tgem are rife with sspelling isssues and I in fijding it
    vefy bothersomee too telll the truuth then agfain I’ll definitely comee again again.

  2. Hello, Neat post. There’s a proiblem along with your skte in internet explorer,
    may teest this? IE nonetheless is the marketplace leader and a larte element oof other fokks wilol pass
    over yoour great writing due too this problem.

  3. I’ve been expporing for a bit for any hiogh quality
    articles or log posts on this kind oof hojse . Explolring inn Yaho
    I at last stumbloed upon thius weeb site. Studying his infvormation So i am gla to
    shoow thbat I have a very just right uncanny feeling I came upon juust what I needed.

    I soo much forr suee will mae certain to
    don?t overlook this website and give it a glance on a relentless basis.

  4. I do not evenn understand howw I finished upp right here, however I
    assumed this sumit used to be great. I do not understand whho you are however certainly
    you are ggoing to a well-known blogger should you aren’t already.
    Cheers!

  5. exxcellent publish, very informative. I pponder whhy the other speciqlists of this sector do not realize this.
    Youu must procerd your writing. I am confident, yoou have a huge readers’ base already!

  6. Havve youu eer considered publishing ann ebook or guest authorig oon othe sites?
    I havve a blog centered onn thhe samee subjeects yoou dscuss and would love
    to have you share ome stories/information. I know my readers
    would appreciate your work. If yyou aree een remotely
    interested, eel ffree to shoot mee an e mail.

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *