Caddy 一键安装及简单配置

一键安装

1
wget -N --no-check-certificate https://raw.githubusercontent.com/Joyace/sh/master/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh

Caddy 使用说明

启动:/etc/init.d/caddy start

停止:/etc/init.d/caddy stop

重启:/etc/init.d/caddy restart

查看状态:/etc/init.d/caddy status

查看Caddy启动日志: tail -f /tmp/caddy.log

安装目录:/usr/local/caddy

Caddy配置文件位置:/usr/local/caddy/Caddyfile

Caddy自动申请SSL证书位置:/.caddy/acme/acme-v01.api.letsencrypt.org/sites/xxx.xxx(域名)/

配置示范

filebrowser

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
http://xxx.com {
 timeouts none
 redir https://xxx.com{url}
}
xxx.com {
 root /usr/local/caddy/www/file
 timeouts none
 tls xxx@mail.com
 gzip
 filebrowser / /usr/local/caddy/www/file {
  database /usr/local/caddy/filebrowser.db
 }
}

typecho

1
apt-get install php7.0-cgi php7.0-fpm php7.0-curl php7.0-gd php7.0-mbstring php7.0-xml php7.0-sqlite3 sqlite3 -y
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
http://xxx.com {
    redir https://xxx.com{url}
    }
    https://xxx.com {
    gzip
    tls xxx@mail.com
    root /typecho
    fastcgi / /run/php/php7.0-fpm.sock php
    rewrite {
        if {path} not_match ^\/admin
        to {path} {path}/ /index.php?{query}
     }
}

wordpress

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
www.moerats.com {
  redir https://xxx.com{url}
}
moerats.com {
  root /wordpress
  tls xxx@mail.com
  gzip
  fastcgi / /run/php/php7.0-fpm.sock php
  rewrite {
    if {path} not_match ^\/wp-admin
    to {path} {path}/ /index.php?{query}
  }
}

Chevereto

1
2
3
4
5
6
7
8
example.com {
    root /var/www/chevereto
    fastcgi / /var/run/php/php7.0-fpm.sock php
​
    rewrite {
        to {path} {path}/ /index.php?{query}
    }
}

Nextcloud

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
my-nextcloud-site.com {
​
    root   /var/www/nextcloud
    log    /var/log/nextcloud_access.log
    errors /var/log/nextcloud_errors.log
​
    fastcgi / 127.0.0.1:9000 php {
        env PATH /bin
    }
    
    # checks for images
        rewrite {
            ext .svg .gif .png .html .ttf .woff .ico .jpg .jpeg
        r ^/index.php/(.+)$
        to /{1} /index.php?{1}
    }
​
    rewrite {
        r ^/index.php/.*$
        to /index.php?{query}
    }
​
    # client support (e.g. os x calendar / contacts)
    redir /.well-known/carddav /remote.php/carddav 301
    redir /.well-known/caldav /remote.php/caldav 301
​
    # remove trailing / as it causes errors with php-fpm
    rewrite {
        r ^/remote.php/(webdav|caldav|carddav|dav)(\/?)(\/?)$
        to /remote.php/{1}
    }
​
    rewrite {
        r ^/remote.php/(webdav|caldav|carddav|dav)/(.+?)(\/?)(\/?)$
        to /remote.php/{1}/{2}
    }
​
    rewrite {
        r ^/public.php/(dav|webdav|caldav|carddav)(\/?)(\/?)$
        to /public.php/{1}
    }
​
    rewrite {
        r ^/public.php/(dav|webdav|caldav|carddav)/(.+)(\/?)(\/?)$
        to /public.php/{1}/{2}
    }
​
    # .htaccess / data / config / ... shouldn't be accessible from outside
    status 403 {
        /.htaccess
        /data
        /config
        /db_structure
        /.xml
        /README
    }
​
    header / Strict-Transport-Security "max-age=31536000;"
​
}

此配置在nextcloud 14上有些问题,至今我无法解决,如果有解决方法请联系我更新。