之前看到一个名为 Nextcloud 的项目,没有注意,只是感觉和 Owncloud 的界面非常相似,大概是有千丝万缕的关系。
然后最近看新闻才知道 Owncloud 母公司破产了,原团队已经出走,新的项目名为 Nextcloud,所以本文将介绍 Nextcloud 的安装配置。
需要说明一下的是,Owncloud并没有停止开发,而是由原来的德国团队接手了,所以你可以继续使用 Owncloud。之前的关于Owncloud的介绍:http://www.jianshu.com/p/792a5c1fa44b
1. 安装 Docker 与 Compose
一贯的风格首先安装 Docker:
curl -sSL https://get.docker.com/ | sh
然后安装 Compose:
curl -L https://github.com/docker/compose/releases/download/1.10.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
这样我们的基本工具就搞定了。
1.1. 配置 Docker 镜像源
接下来我们会拉取几个镜像,默认的镜像仓库在海外,速度不理想,所以我们使用国内的镜像源,这里以中科大的为例:
首先编辑文件 /etc/docker/daemon.json,在该配置文件中加入下面内容(没有该文件的话建一个):
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"]
}
保存之后最好重启一下 Docker 服务,这样就可以使用国内镜像源拉取镜像了。
1.2. 部署 NextCloud
首先为Nextcloud建立一个独立的容器网络:
docker network create nextcloud
接下来新建一个文件夹,名字随便,这里演示为cloud,然后在文件夹里面新建一个文件,文件名为Caddyfile,文件内容如下:
example.com {
proxy / 233.233.233.233:2333 {
proxy_header Host {host}
proxy_header X-Real-IP {remote}
proxy_header X-Forwarded-Proto {scheme}
}
log /var/log/caddy.log
gzip
}
因为使用Caddy部署应用不需要花费诸位太多时间去配置Web服务器环境,所以我这里使用Caddy,实际上如果你喜欢Nginx,自己修改下面的配置就好了。Caddy适合不想写配置或者懒得动手申请SSL的读者。
接下来再新建一个文件,名为docker-compose.yml,文件的内容如下:
version: '2'
services:
db:
container_name: cloud_db
image: mysql
volumes:
- "./data/cloud/mysql:/var/lib/mysql"
restart: always
environment:
MYSQL_ROOT_PASSWORD: 这里填写你的密码
MYSQL_DATABASE: nextcloud
app:
container_name: cloud_app
depends_on:
- db
image: nextcloud
volumes:
- ./data/cloud/config:/var/www/html/config
- ./data/cloud/data:/var/www/html/data
- ./data/cloud/apps:/var/www/html/apps
links:
- db
ports:
- "2333:80"
restart: always
cron:
container_name: cloud_cron
image: nextcloud
links:
- db
volumes_from:
- app
user: www-data
entrypoint: |
bash -c 'bash -s <<EOF
trap "break;exit" SIGHUP SIGINT SIGTERM
while /bin/true; do
/usr/local/bin/php /var/www/html/cron.php
sleep 900
done
EOF'
restart: always
web:
container_name: cloud_web
image: abiosoft/caddy
volumes:
- ./Caddyfile:/etc/Caddyfile
- ~/.caddy:/root/.caddy
ports:
- 80:80
- 443:443
restart: always
networks:
default:
external:
name: nextcloud
保存文件之后,一句话启动它~~
docker-compose up -d
上面文件内容只有那个密码是需要你改的,其他不变即可。
稍微去喝杯茶,一会回来你就可以看到Nextcloud部署成功了。

配置数据库自己根据需要修改,打算一个人用,就用Sqlite,很多人用就用MySQL之类的吧。

你的用户名就是 root,数据库地址是 db,不是 localhost。
2. 配置 NextCloud
安装完成还要做两件事,当然不是必须的,但是为了安全起见,最好再折腾一下。
2.1. 配置两步验证
两步验证可以防暴力入侵什么的,建议使用。首先在后台启用两步验证,然后手机安装下面的应用:
https://play.google.com/store/apps/details?id=com.google.android.apps.authenticator2
登录时需要手机上的离线验证码验证,安全有了多一层保障。
2.2. 客户端安装与使用
首先客户端几乎是全平台的,地址在下面:
https://nextcloud.com/install/#install-clients
因为开启了二步验证,在客户端直接使用帐号密码肯定无法登录了,所以需要在后台设置应用密码,地址格式:
http://你的地址/index.php/settings/personal#apppasswords
在设置中设置应用一次性密码,使用随机密码登录客户端即可。

网友评论
—
自己在简书总结了一下过程,给后来人参考。地址www.jianshu.com/p/287ac71ef6c5
example.com {
proxy / 233.233.233.233:2333 {
proxy_header Host {host}
proxy_header X-Real-IP {remote}
proxy_header X-Forwarded-Proto {scheme}
}
log /var/log/caddy.log
gzip
}
在这里面加吗?
error shile trying to create admin user :failed to connect tothe database :An exception occured in driver:SQLSTATE[HY000][1045]Access denied for user 'admin'@'172.18.0.4'(using password:YES)
ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running?
If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.
latest: Pulling from abiosoft/caddy
019300c8a437: Pull complete
fe70aec6194a: Pull complete
ee58fa05329b: Pull complete
801087373cad: Pull complete
51a722215450: Pull complete
Digest: sha256:0ebb96d28b2cf895cb73fec9abadb5d6efec422b8dea348ea25b9a5a194b8500
Status: Downloaded newer image for abiosoft/caddy:latest
Pulling db (mysql:latest)...
latest: Pulling from library/mysql
ad74af05f5a2: Pull complete
0639788facc8: Pull complete
de70fa77eb2b: Pull complete
724179e94999: Pull complete
50c77fb16ba6: Pull complete
d51f459239fb: Pull complete
937bbdd4305a: Pull complete
35369f9634e1: Pull complete
f6016aab25f1: Pull complete
5f1901e920da: Pull complete
fdf808213c5b: Pull complete
Digest: sha256:96edf37370df96d2a4ee1715cc5c7820a0ec6286551a927981ed50f0273d9b43
Status: Downloaded newer image for mysql:latest
Pulling app (nextcloud:latest)...
latest: Pulling from library/nextcloud
ad74af05f5a2: Already exists
a1e75557f244: Pull complete
6ab4f72a86ad: Pull complete
55e3508d42ca: Pull complete
88792c88e1bc: Pull complete
1d8a48cffe59: Pull complete
0c30cf9b4233: Pull complete
37ec3cd3c9fb: Pull complete
1925fdff3f6a: Pull complete
f1a75ee98d0d: Pull complete
b9e0483f0c09: Pull complete
8c5d8b4070d7: Pull complete
ffd7c73efd91: Pull complete
08e4147cf867: Pull complete
0477917c63c6: Pull complete
76b0436bed6e: Pull complete
29c14558bf95: Pull complete
ccac2e7f0ba2: Pull complete
b44334ad4f4a: Pull complete
4a3eaa4e9c38: Pull complete
c7a793b81da9: Pull complete
Digest: sha256:1fc730dd9b7f3663c391d0bba05385eca4f107d070bc1b2cbe2713743e0cf9f5
Status: Downloaded newer image for nextcloud:latest
Creating cloud_db
Creating cloud_web
Creating cloud_app
Creating cloud_cron
访问空白页是什么情况呀??? ip:2333 昨天莫名都没事 今天 重新装了下 访问空白
: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
ERROR: Encountered errors while bringing up the project.
请问下这是很么情况但是访问地址 ip:2333 是可以访问
这个域名是指什么域名?云服务器的域名吗?还是其他,求解答
[root@vultr nextcloud]# docker-compose up -d
ERROR: The Compose file './docker-compose.yml' is invalid because:
Additional properties are not allowed ('web' was unexpected)
You might be seeing this error because you're using the wrong Compose file version. Either specify a supported version ("2.0", "2.1", "3.0") and place your service definitions under the `services` key, or omit the `version` key and place your service definitions at the root of the file to use version 1.
For more on the Compose file format versions, see https://docs.docker.com/compose/compose-file/
您可以由 <a href="https://docs.nextcloud.com/server/11/go.php?to=admin-dir_permissions" target="_blank" rel="noreferrer"> 设置 Web 服务器对 config 目录 </a> 的写权限修复这个问题
怎么解决
尝试了chmod 771 /root/cloud/data/cloud/config/config.php
和chgrp www-data /root/cloud/data/cloud/config
但是没有效果