[chevereto]图床

打算搭建图床,网上常用的有LycheeChevereto,记录一下使用docker compose方式安装chevereto

基本配置

  • 服务器:腾讯云服务器
  • 操作系统:Ubuntu 18.04
  • Docker:19.03.11
  • Docker Compose:1.26.0
  • Chevereto (Free): 1.1.4

docker-compose

使用docker-compose方式配置chevereto以及相应的数据库mariadb

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
version: '3'

services:
db:
image: mariadb
volumes:
- database:/var/lib/mysql:rw
restart: always
networks:
- private
environment:
MYSQL_ROOT_PASSWORD: chevereto_root
MYSQL_DATABASE: chevereto
MYSQL_USER: chevereto
MYSQL_PASSWORD: chevereto

chevereto:
depends_on:
- db
image: nmtan/chevereto
restart: always
networks:
- private
environment:
CHEVERETO_DB_HOST: db
CHEVERETO_DB_USERNAME: chevereto
CHEVERETO_DB_PASSWORD: chevereto
CHEVERETO_DB_NAME: chevereto
CHEVERETO_DB_PREFIX: chv_
volumes:
- chevereto_images:/var/www/html/images:rw
ports:
- 8080:80

networks:
private:
volumes:
database:
chevereto_images:
  • 数据保存在卷databasechevereto_images
  • 主机端口号为8080

启动容器命令即可:

1
$ docker-compose up -d

扩展图像大小

默认情况下,chevereto仅支持最大为2MB的图像上传,根据官网(Max image size)的描述,这是由于PHP语言的限制,需要额外编写配置文件。参考:

Chevereto supports only 2MB Max Upload size

need help with php.ini and its upload limit size for a docker container

docker 的官方PHP镜像 如何修改 php.ini 配置

docker-compose.yml同一路径下编辑配置文件chevereto.ini

1
2
3
4
5
$ cat chevereto.ini 
memory_limit = 256M;
upload_max_filesize = 100M;
post_max_size = 100M;
max_execution_time = 60;

修改docker-compose.yml,将配置文件复制到容器内

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
。。。
。。。
chevereto:
depends_on:
- db
image: nmtan/chevereto
restart: always
networks:
- private
environment:
CHEVERETO_DB_HOST: db
CHEVERETO_DB_USERNAME: chevereto
CHEVERETO_DB_PASSWORD: chevereto
CHEVERETO_DB_NAME: chevereto
CHEVERETO_DB_PREFIX: chv_
volumes:
- chevereto_images:/var/www/html/images:rw
- ./chevereto.ini:/usr/local/etc/php/conf.d/chevereto.ini <-------- 这里
ports:
- 12351:80
。。。
。。。

重新启动容器,图片最大上传大小限制就修改了

1
$ docker-compose up -d

可进入右上角用户 -> 仪表盘进行查看

Nginx+SSL

使用Nginx进行代理,同时添加SSL认证

  • 下载阿里云的域名和证书
  • 下载Nginx Docker,进行配置

可以将NginxChevereto一起在docker-compose.yml中进行配置,不过为了复用反向代理服务,所以单独写一个docker-compose.yml配置Nginx。如何配置Nginx参考docker安装nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ cat docker-compose.yml 
version: "3"
services:
nginx:
container_name: nginx
image: nginx
ports:
- "9300:9300"
volumes:
- "~/software/nginx/cert:/etc/nginx/cert" <---------- 将证书放置在这里
- "~/software/nginx/www:/opt/www"
- "~/software/nginx/logs:/var/log/nginx"
- "~/software/nginx/conf.d:/etc/nginx/conf.d"
- "~/software/nginx/nginx.conf:/etc/nginx/nginx.conf"
restart: always

关于Chevereto的配置信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ cat chevereto.conf 
server {
listen <填写对外的端口号,比如9300> ssl;
server_name <填写自己的域名>;

ssl_certificate cert/chevereto.pem; #将domain name.pem替换成您证书的文件名。
ssl_certificate_key cert/chevereto.key; #将domain name.key替换成您证书的密钥文件名。
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

location / {
proxy_set_header X-Rea $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Nginx-Proxy true;
proxy_pass http://xxx.xxx.xxx.xxx:12351; <------------ 修改这里
proxy_set_header X-Forwarded-Proto $scheme;
}
}

完成上述配置后,启动Nginx,即可实现反向代理+SSL服务

sherlon.png