Skip to content

Latest commit

 

History

History
112 lines (96 loc) · 2.36 KB

Caddy.md

File metadata and controls

112 lines (96 loc) · 2.36 KB

安装 Caddy

添加 alidns Dockerfile

FROM caddy:2.4.6-builder-alpine AS builder

RUN go env -w GOPROXY=https://goproxy.cn

RUN xcaddy build --with github.com/caddy-dns/alidns

FROM caddy:2.4.6-alpine

COPY --from=builder /usr/bin/caddy /usr/bin/caddy
vim ~/caddy/docker-compose.yml
------------------
version: '3.8'

services:
  caddy:
    image: caddy:2.4.6-alpine
    container_name: caddy
    network_mode: host
    hostname: caddy
    domainname: caddy
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - $PWD/Caddyfile:/etc/caddy/Caddyfile
      - $PWD/site:/site
      - $PWD/ssl:/ssl
      - data:/data
      - config:/config

volumes:
  data:
  config:
------------------
docker-compose up -d

Caddyfile

import /vhost/*

test.toby.vip {
  encode gzip
  tls /ssl/toby.vip.pem /ssl/toby.vip.key
  reverse_proxy localhost:9000 {
    header_up Host {http.request.host}
    header_up X-Real-IP {http.request.remote.host}
    header_up X-Forwarded-For {http.request.remote.host}
    header_up X-Forwarded-Port {http.request.port}
  }
}

test1.toby.vip {
  encode gzip
  tls toby@toby.vip
  handle_path /dir1/* {
    reverse_proxy localhost:9001 {
      header_up Host {http.request.host}
      header_up X-Real-IP {http.request.remote.host}
      header_up X-Forwarded-For {http.request.remote.host}
      header_up X-Forwarded-Port {http.request.port}
    }
  }
  handle_path /dir2/* {
    reverse_proxy localhost:9002 {
      header_up Host {http.request.host}
      header_up X-Real-IP {http.request.remote.host}
      header_up X-Forwarded-For {http.request.remote.host}
      header_up X-Forwarded-Port {http.request.port}
    }
  }
}

file.toby.vip {
  encode gzip
  tls /ssl/toby.vip.pem /ssl/toby.vip.key
  root * /site/{name}
  file_server
  try_files {path} {path}/ /index.html
}

*.test.toby.vip {
   encode gzip
   tls {
     dns alidns {
       access_key_id {env.ALIYUN_ACCESS_KEY_ID}
       access_key_secret {env.ALIYUN_ACCESS_KEY_SECRET}
     }
   }
   reverse_proxy https://*.test.toby.vip:18443 {
     transport http {
       tls_insecure_skip_verify
     }
     header_up Host {http.request.host}
     header_up X-Real-IP {http.request.remote.host}
     header_up X-Forwarded-For {http.request.remote.host}
     # jetty 可能无法兼容 X-Forwarded-Port
     # header_up X-Forwarded-Port {http.request.port}
   }
}