caddy v1

caddy,Fast, cross-platform HTTP/2 web server with automatic HTTPS

Caddyfile

 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 127.0.0.1 hao.laijw.com
# 127.0.0.1 blog.laijw.com
# 127.0.0.1 doc.laijw.com
# 127.0.0.1 gosuv.laijw.com
# 127.0.0.1 static.local.laijw.com
# 127.0.0.1 gogs.laijw.com
# 127.0.0.1 resume.laijw.com
# 127.0.0.1 sandman.laijw.com
# 127.0.0.1 academic.laijw.com


# 静态站点

http://hao.laijw.com {
  root D:\WWW\go\hugo-startpage\public
  gzip
}

http://resume.laijw.com {
  root D:\WWW\go\pdf-resume
  gzip
}

http://blog.laijw.com {
  root D:\WWW\go\hugo-laijw\public
  gzip

  errors {
    404 404.html
  }
}

http://doc.laijw.com {
  root D:\WWW\go\hugo-docs\public
  gzip

  errors {
    404 404.html
  }
}

http://academic.laijw.com {
  root D:\WWW\go\hugo-academic\public
  gzip

  errors {
    404 404.html
  }
}


# 反向代理

http://static.local.laijw.com {
  proxy / localhost:9090
}

http://sandman.laijw.com {
  proxy / localhost:9080
}

http://gosuv.laijw.com {
  proxy / localhost:11313 {
    websocket
    transparent
  }
}

http://gogs.laijw.com {
  proxy / localhost:9095 {
    except /css /fonts /js /img
  }
  root D:\down\go\gogs\public
}

Install

1
curl https://getcaddy.com | bash -s personal http.cache,http.git,http.supervisor,hook.service

caddy -service

caddy -service,可以将 caddy 注册到服务

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# 将 caddy 注册到服务
caddy -service install -agree -email laijingwei1993@163.com -conf /www/Caddyfile

# Windows 需在管理员身份运行
caddy -service install -agree -email laijingwei1993@163.com -conf D:\down\go\caddy\Caddyfile

# 相关命令
caddy -service start
caddy -service restart
caddy -service stop
caddy -service uninstall

caddy php 环境

安装 php 7.2

1
2
apt install -y mysql-server
apt install -y php7.2-fpm php7.2-gd php7.2-mysql php7.2-opcache

Caddyfile

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
http://fast.laijw.com {
  cache
  root /www/fast.laijw.com/public
  gzip
  fastcgi / /run/php/php7.2-fpm.sock php {
    ext .php
    split .php
    index index.php
  }
  rewrite {
    to {path} {path}/ /index.php?/{uri}
  }
}

设置 MySQL

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//登录MySQL
sudo mysql -u root

//删除root账号
drop user 'root'@'localhost';

//新建root账号,并设密码
create user 'root'@'%' identified by '123456';

//给root账号授权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

//使上述配置生效
flush privileges;

//退出
exit

//修改配置
vim /etc/mysql/mysql.conf.d/mysqld.cnf

//注释这行
bind-address = 127.0.0.1

caddy-supervisor

caddy-supervisor,可以用来守护进程

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
http://api.laijw.com {
	supervisor {
		command sandman2ctl
		args sqlite+pysqlite:///sandman2.db -p 9080
		dir /www/sandman2
	}
	
	cache
	proxy / localhost:9080
}

Caddyfile

 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
http://0.0.0.0, laijw.com, www.laijw.com, http://laijw.com, http://www.laijw.com {
  root /www/laijw.com
  gzip

  errors {
    404 404.html
  }

  git {
    repo https://gitee.com/laijingwei/laijw.com.git
    path /www/laijw.com
    interval -1
    hook /webhook 123456
  }
}

http://api.laijw.com {
  supervisor {
    command sandman2ctl
    args sqlite+pysqlite:///sandman2.db -p 9080
    dir /www/sandman2
  }

  cache
  proxy / localhost:9080
}

http://gitea.laijw.com {
  cache
  proxy / 203.195.167.93:3000
}

http://sanhu.laijw.com {
  root /www/sanhu.laijw.com
  gzip

  rewrite {
    if {path} not_has /api
    to {path} /
  }

  proxy /api api.h114.weipinpai.top:90 {
    without /api
  }
}

Caddy v2

1
2
3
4
5
brew install caddy

brew service start caddy
caddy start
caddy reload

Caddyfile

Caddy 2 文档

 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
http://book.local.laijw.com {
  encode gzip
  file_server
  root * /Volumes/E/app/laijw.com/book-docs/book
}

http://vim.local.laijw.com {
  encode gzip
  file_server
  root * /Volumes/D/WWW/hugo/book-vim/book
}

http://pass.local.laijw.com {
  encode gzip
  file_server
  root * /Volumes/D/WWW/hugo/hugo-pass/public
}

http://blog.local.laijw.com {
  encode gzip
  file_server
  root * /Volumes/D/WWW/hugo/hugo-laijw/public
}

http://hyper.local.laijw.com {
  encode gzip
  file_server
  root * /Volumes/E/app/jdy/hyperf-admin/docs
}

http://jdy.local.laijw.com {
  reverse_proxy 127.0.0.1:9528
}

http://jdn.local.laijw.com {
  encode gzip
  file_server
  root * /Volumes/E/app/jdy/A/hyperf-admin-frontend/dist
  redir / /system/
  route /api/* {
    uri strip_prefix /api
    reverse_proxy kjd.api.huizhouyiren.com:7501
  }
}