ubuntu24.04使用docker搭建nextcloud

先按照 这里配置docker

然后使用 docker compose 配置,更新简单

创建docker-compose文件

创建 docker-compose.yaml 文件,内容如下

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
services:
mysql:
# https://hub.docker.com/_/mysql/tags
image: mysql:8.3.0
container_name: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
volumes:
- /data/docker_apps/mysql:/var/lib/mysql
environment:
- MYSQL_HOST=mysql
- MYSQL_ROOT_PASSWORD=12345678
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=oc_icpcs
- MYSQL_PASSWORD=dveewewrwvc
networks:
- icpcs
redis:
# https://hub.docker.com/_/redis/tags
image: redis:7.2.4
command: redis-server /etc/redis/redis.conf --appendonly yes --requirepass 'nc_redis'
restart: always
privileged: true
volumes:
- /data/docker_apps/redis/redis.conf:/etc/redis/redis.conf
- /data/docker_apps/redis/data:/data
container_name: redis
networks:
- icpcs
nextcloud:
# https://hub.docker.com/_/nextcloud/tags
image: nextcloud:29.0.0
container_name: nextcloud
restart: always
volumes:
- /data/docker_apps/nextcloud:/var/www/html
depends_on:
- mysql
- redis
ports:
- 81:80
links:
- mysql
- redis
environment:
- MYSQL_HOST=mysql
- MYSQL_ROOT_PASSWORD=12345678
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=oc_icpcs
- MYSQL_PASSWORD=dveewewrwvc
- REDIS_HOST=redis
- REDIS_HOST_PASSWORD=nc_redis
networks:
- icpcs

networks:
icpcs:
driver: bridge
ipam:
config:
- subnet: 10.15.0.0/16
gateway: 10.15.0.1

  • 注意,10.15.0 不要与本地网络其他ip冲突
  • 版本为 nextcloud:29.0.0 可以在 docker-hub 查看有哪些版本
  • 数据库密码为 dveewewrwvc 上面出现了两次,修改的话注意
  • redismysql 数据库版本不要轻易修改

创建本地数据目录

这里数据都放在了 /data/docker_apps/mysql/data/docker_apps/nextcloud/data/docker_apps/redis 这里,你也可以放在其他地方,但是注意上面docker-compose文件中对应的路径也要修改

1
2
3
mkdir /data/docker_apps/mysql
mkdir /data/docker_apps/postgresql
mkdir /data/docker_apps/redis

如果要绑定在二级目录,配置文件中,这两个应该起到了作用

1
vim /data/docker_apps/nextcloud/config/config.php
1
2
3
4
'overwrite.cli.url' => 'https://xxxx.cn/nc/',
'overwritehost' => 'xxxx.cn',
'overwritewebroot' => '/nc',
'overwriteprotocol' => 'https',

同时 nginx 配置

1
vim /etc/nginx/sites-enabled/nc.conf

下面只是部分,可能需要修改

client_max_body_size 1024m; 很重要

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
server {
listen 82;
server_name xxxx.cn;

absolute_redirect off;
#上传会被限制
client_max_body_size 1024m;

location = /.well-known/carddav {
return 301 https://$server_name/nc/remote.php/dav;
}
location = /.well-known/caldav {
return 301 https://$server_name/nc/remote.php/dav;
}
location = /.well-known/host-meta {
return 301 https://$server_name/nc/public.php?service=host-meta;
}
location = /.well-known/host-meta.json {
return 301 https://$server_name/nc/public.php?service=host-meta-json;
}
location = /.well-known/webfinger {
return 301 https://$server_name/nc/index.php/.well-known/webfinger;
}
location = /.well-known/nodeinfo {
return 301 https://$server_name/nc/index.php/.well-known/nodeinfo;
}

location /nc/ {
#add_header Set-Cookie "__Host-Prefix=true; Path=/nc; Secure; SameSite=Strict";
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains; preload;" always;
add_header X-Download-Options noopen;
proxy_set_header Host $host;

proxy_pass http://localhost:81/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}

nextloud配置

初始化 网址路径,需要填写数据库用户名密码在上面文件中,即

1
2
- MYSQL_USER=oc_icpcs
- MYSQL_PASSWORD=dveewewrwvc

用户名 oc_icpcs,密码 dveewewrwvc,用的 mysql

安装

docker-compose.yaml 文件所在目录,执行

注意最新版没有 docker-compose

1
docker compose up -d

更新

直接再次在 docker-compose.yaml 文件所在目录运行这个命令即可

1
docker compose up -d

本文作者:yuhldr
本文地址: https://yuhldr.github.io/posts/ec194a20.html
版权声明:转载请注明出处!