下面安装以Docker Compose方式安装为例,介绍怎么安装NextCloud,选择MySQL作为数据库。
这里就不介绍,怎么安装Docker和Docker Compose了,具体请自行学习。
1、创建NextCloud项目文件夹和Nginx conf.d文件夹
1)为nginx的配置文件创建一个conf.d文件夹
mkdir -p /opt/nextcloud/conf.d
2)创建 nextcloud.conf nginx 配置文件
nano /opt/nextcloud/conf.d/nextcloud.conf
3)将以下信息复制到 nextcloud.conf 文件中。
upstream php-handler { server app:9000; } server { listen 80; listen 443 ssl http2; server_name ${FQDN}; # Max allowed upload file in web page client_max_body_size 20G; if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; } # SSL and Support TLSv1.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; # add header information to fix Nextcloud console warning messages 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; } # Enable gzip compression 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; # redirection and disable to access backend sensitive folders and resources 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 configuration 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; } }
2、 创建一个新的Nextcloud docker-compose文件
nano /opt/nextcloud/docker-compose.yml
1)用DB创建一个新的Nextcloud docker-compose文件
将以下信息复制到刚才创建好的文件中
version: '3' volumes: letsencrypt: nextcloud: services: proxy: image: staticfloat/nginx-certbot ports: - 80:80 - 443:443 environment: CERTBOT_EMAIL: example@itmao.club ENVSUBST_VARS: FQDN FQDN: nextcloud.itmao.club 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=Password1234!@ - MYSQL_PASSWORD=Password1234!@ - 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
2)上述配置文件中,你需要修改的有以下几个地方:
需要修改邮箱和绑定的域名
CERTBOT_EMAIL: example@itmao.club ENVSUBST_VARS: FQDN FQDN: nextcloud.itmao.club
MySQL密码和用户配置
- MYSQL_ROOT_PASSWORD=Password1234!@ - MYSQL_PASSWORD=Password1234!@ - MYSQL_DATABASE=nextcloud - MYSQL_USER=nextcloud
注释事项:
运行之前,要先创建DNS,域名A记录,上述文件的示例域名为:nextcloud.itmao.club,指向你需要配置的服务器的公网IP。
在打开防火墙的80和443端口,这些配置完成后,可以执行docker-compose命令启动你的docker。
cd /opt/nextcloud
docker-compose up -d
耐心等待安装并且启动结束后,可以用浏览器访问域名:https://nextcloud.itmao.club
输入刚才的docker compose配置文件的配置信息进行安装。
3、安装完成后1)安装完成后,有几件事情需要清理和进一步配置。
安装Docker后,我们将不得不运行以下两个命令来修复设置警告。
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
2)在您的 nextCloud 用户下添加本地文件夹
例如,如果您的 nextcloud 用户是管理员,您想在该用户下添加您的本地文件,您需要将所有文件复制到以下文件夹
/opt/nextcloud/app/data/admin/files
3)将所有文件复制到这个文件夹后,使用下面的命令来扫描它们。
docker-compose exec -u www-data app php occ files:scan --all
4)如果你想安装ffmpeg,请按照这些命令。
docker exec -it nextcloud_app_1 bash
apt -y update
apt -y install ffmpeg
4、备份和恢复
以下是备份和恢复你的NextCloud系统的一些步骤。
1)使用docker-compose命令停止所有正在运行的dockers。
cd /opt/nextcloud
docker-compose stop
2)从/opt/nextcloud文件夹打包所有文件
cd /opt
tar -zcvf nextcloud.tar.gz nextcloud
3)传输tar文件到新机器
scp nextcloud.tar.gz root@serverip:/opt
3)在新机器上安装Docker和Docker Compose
cd /opt
tar -xzvf nextcloud.tar.gz
4)用刚才的配置文件启动docker
cd nextcloud
docker-compose up -d