前两天用snap装了个nextcloud后来发现实在是太封闭了,几乎什么配置都不能自己改,然后就只是开关了一下ssl就boom了。难受的一批,亏我还传了50多G的“学习资料”上去。。
最后决定还是用docker吧,看了下dockerhub上的配置没符合自己需求的,就自己花了一点时间撸了一个docker-compose,可以说我只是尽量在把这篇文章里面的东西给容器化:
首先安装docker:
apt -y update apt -y install curl curl -sSL https://get.docker.com/ | sh systemctl start docker systemctl enable docker
安装docker-compose:
curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose
接着新建一个docker-compose的项目目录以及conf.d目录(conf.d用于存放nginx配置文件):
mkdir -p /opt/nextcloud/conf.d
新建nginx配置文件:
nano /opt/nextcloud/conf.d/nextcloud.conf
直接粘贴下面的内容,什么都不用改动:
upstream php-handler { server app:9000; } server { listen 80; listen 443 ssl http2; server_name ${FQDN}; # WEB页面允许最大的文件上传大小 client_max_body_size 20G; if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; } # SSL以及TLS1.3支持 ssl_certificate /etc/letsencrypt/live/${FQDN}/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/${FQDN}/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; ssl_ciphers TLS13-AES-256-GCM-SHA384:TLS13-CHACHA20-POLY1305-SHA256:TLS13-AES-128-GCM-SHA256:TLS13-AES-128-CCM-8-SHA256:TLS13-AES-128-CCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; error_page 497 https://$host$request_uri; # 添加头信息修复Nextcloud后台的警告信息 add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Permitted-Cross-Domain-Policies none; add_header Referrer-Policy no-referrer; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; fastcgi_hide_header X-Powered-By; root /var/www/html; location = /robots.txt { allow all; log_not_found off; access_log off; } location = /.well-known/carddav { return 301 $scheme://$host/remote.php/dav; } location = /.well-known/caldav { return 301 $scheme://$host/remote.php/dav; } # 启用Gzip压缩 gzip on; gzip_vary on; gzip_comp_level 4; gzip_min_length 256; gzip_proxied expired no-cache no-store private no_last_modified no_etag auth; gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; # 重定向以及禁止访问敏感目录和资源 location / { rewrite ^ /index.php$request_uri; } location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ { deny all; } location ~ ^/(?:.|autotest|occ|issue|indie|db_|console) { deny all; } # PHP配置 location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+).php(?:$|/) { fastcgi_split_path_info ^(.+?.php)(/.*|)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param HTTPS on; #Avoid sending the security headers twice fastcgi_param modHeadersAvailable true; fastcgi_param front_controller_active true; fastcgi_pass php-handler; fastcgi_intercept_errors on; fastcgi_request_buffering off; } location ~ ^/(?:updater|ocs-provider)(?:$|/) { try_files $uri/ =404; index index.php; } location ~ .(?:css|js|woff2?|svg|gif)$ { try_files $uri /index.php$request_uri; add_header Cache-Control "public, max-age=15778463"; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; add_header Referrer-Policy no-referrer; access_log off; } location ~ .(?:png|html|ttf|ico|jpg|jpeg)$ { try_files $uri /index.php$request_uri; # Optional: Don't log access to other assets access_log off; } }
接着新建docker-compose的配置文件:
nano /opt/nextcloud/docker-compose.yml
粘贴下面的内容:
version: '3' volumes: letsencrypt: nextcloud: services: proxy: image: staticfloat/nginx-certbot ports: - 80:80 - 443:443 environment: CERTBOT_EMAIL: [email protected] ENVSUBST_VARS: FQDN FQDN: nextcloud.233.fi volumes: - ./conf.d:/etc/nginx/user.conf.d:ro - letsencrypt:/etc/letsencrypt - nextcloud:/var/www/html restart: unless-stopped db: image: mariadb environment: - MYSQL_ROOT_PASSWORD= - MYSQL_PASSWORD= - MYSQL_DATABASE=nextcloud - MYSQL_USER=nextcloud volumes: - ./mysql:/var/lib/mysql restart: unless-stopped app: image: nextcloud:fpm volumes: - nextcloud:/var/www/html - ./app/data:/var/www/html/data - ./app/config:/var/www/html/config restart: unless-stopped cron: image: rcdailey/nextcloud-cronjob environment: - NEXTCLOUD_CRON_MINUTE_INTERVAL=15 - NEXTCLOUD_CONTAINER_NAME=app - NEXTCLOUD_PROJECT_NAME=nextcloud volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - /etc/localtime:/etc/localtime:ro restart: always
在上面这个配置文件内你需要改动的地方有以下几点:
1.CERTBOT_EMAIL设置你的邮箱地址
2.FQDN: nextcloud.233.fi换成你自己的域名(提前解析到你的VPS或是服务器上)
3.MYSQL_ROOT_PASSWORD=设置你的数据库root密码
4.MYSQL_PASSWORD=设置你的数据库用户密码(nextcloud这个用户的密码)
确认无误后up起来即可:
cd /opt/nextcloud docker-compose up -d
打开你的域名在安装界面这块设置你的管理员账号密码,数据库选择MySQL,注意数据库主机这里要把localhost改为db:
安装完成之后,修复后台概览中的安全及设置警告:
docker-compose exec -u www-data app php occ db:add-missing-indices docker-compose exec -u www-data app php occ db:convert-filecache-bigint
从本地添加文件到nextcloud内,添加文件的路径(imlala替换成你自己的用户名):
/opt/nextcloud/app/data/imlala/files
之后执行下面的命令扫描即可:
docker-compose exec -u www-data app php occ files:scan --all
如果需要安装ffmpeg:
docker exec -it nextcloud_app_1 bash apt -y update apt -y install ffmpeg
其他的东西都同理,切到容器内安装就行,不过建议别到容器内瞎折腾,容易BOOM。
下面演示一下备份和迁移的步骤。为了备份/迁移更方便,这个docker-compose内我将mysql以及nextcloud的data都配置成了匿名卷的形式,这样后续备份的时候直接打包这个docker-compose的目录即可。
旧机器内停止运行:
cd /opt/nextcloud docker-compose stop
然后打包:
cd /opt tar -zcvf nextcloud.tar.gz nextcloud
将压缩包传到新机器上:
scp nextcloud.tar.gz root@serverip:/opt
新机器内安装好docker和docker-compose后解压压缩包
cd /opt tar -xzvf nextcloud.tar.gz
进入到docker-compose目录直接up即可完成迁移:
cd nextcloud docker-compose up -d
LALA
我什么都不卖了,告辞!
最新评论
5211314
能不能教我 一点不会