注: 本文使用的是ubuntu系统
一. 安装docker和docker-compose。
使用docker有一个好处就是不管怎么折腾docker里的东西对宿主机豆没有影响,并且环境都是搭建好的,不容易出很多配置问题。
apt install docker.io
apt install docker-compose
二. 创建一个文件,命名为docker-compose.yml(注意修改里面的db_name和db_Password)
nextcloud:
image: wonderfall/nextcloud
links:
- nextcloud-db:nextcloud-db
environment:
- UID=1000
- GID=1000
- UPLOAD_MAX_SIZE=10G
- APC_SHM_SIZE=128M
- OPCACHE_MEM_SIZE=128
- CRON_PERIOD=15m
- TZ=Aisa/Shanghai
- ADMIN_USER=allen
- ADMIN_PASSWORD=pwd
- DOMAIN=localhost
- DB_TYPE=mysql
- DB_NAME=nextcloud
- DB_USER=nextcloud
- DB_PASSWORD=pwd
- DB_HOST=nextcloud-db
volumes:
- /docker/nextcloud/data:/data
- /docker/nextcloud/config:/config
- /docker/nextcloud/apps:/apps2
- /docker/nextcloud/themes:/nextcloud/themes
ports:
- 127.0.0.1:8888:8888/tcp
nextcloud-db:
image: mariadb:10
volumes:
- /docker/nextcloud/db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=pwd
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=pwd
三. 使用docker-compose自动构建docker镜像
docker-compose up -d
四. 检查docker运行情况
docker ps #里面会有两个docker镜像,一个是nextcloud的,一个是数据库的
五. 配置nginx反向代理
配置文件如下,注意这是https的配置,需要先申请一个免费证书,如果不会申请或者有问题可以在下面回复我。
server {
listen 80;
server_name abc.example.com;
return 301 https://$host$request_uri;
}
server {
server_name nextpan.net www.nextpan.net;
listen 443 ssl http2;
ssl on;
ssl_certificate /etc/letsencrypt/live/abc.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/abc.example.com/privkey.pem;
include /etc/nginx/conf/ssl_params.conf;
client_max_body_size 10G;
location / {
proxy_redirect off;
proxy_pass http://127.0.0.1:8888;
proxy_set_header Host $http_host;
add_header Strict-Transport-Security "max-age=15552000; includeSubDomains; preload" always;
include /etc/nginx/conf/proxy_params;
}
location = /.htaccess {
return 404;
}
}
然后重启nginx即可
nginx -t
service nginx restart