最新的帖子

安装NextCloud Docker并与Nginx和Letsencrypt SSL证书集成

以前,我有几个帖子呈现如何安装nextCloud以及如何使用一些不同的存储选项配置它。此帖子与其中之一类似,但它将添加两个Dockers以添加nginx的SSL证书。

这是所有步骤。对于码头组成文件,有两个选项,一个带有MySQL DB,另一个没有DB,下则将使用内置SQLite进行DB。


安装Docker和Docker Compose

1Ubuntu 18.04更新包列表和升级软件包

将Ubuntu更新并升级到最新

$ sudo apt-get -y update && sudo apt-get -y upgrade

2在Ubuntu上安装Docker

sudo apt install docker.io -y
sudo -i
systemctl start docker
systemctl enable docker
docker version
3在Ubuntu上安装Docker Compose


[email protected]:~# curl -L "//github.com/docker/compose/releases/download/1.19.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   651  100   651    0     0   7076      0 --:--:-- --:--:-- --:--:--  7076
100 8288k  100 8288k    0     0  4671k      0  0:00:01  0:00:01 --:--:-- 7520k
[email protected]:~# chmod +x /usr/local/bin/docker-compose

[email protected]:~# docker-compose version
docker-compose version 1.19.0, build 9e633ef
docker-py version: 2.7.0
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
[email protected]:~#


创建NextCloud项目文件夹和nginx conf.d文件夹

为nginx配置文件创建一个conf.d文件夹

mkdir -p /opt/nextcloud/conf.d

创建一个nutcloud.conf nginx配置文件

nano /opt/nextcloud/conf.d/nextcloud.conf


将以下信息复制到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-安全 "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;
    }
}



创建一个新的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: [email protected].com
            ENVSUBST_VARS: FQDN
            FQDN: nextcloud.51sec.org
        volumes:
            - ./conf.d:/etc/nginx/user.conf.d:ro
            - letsencrypt:/etc/letsencrypt
            - nextcloud:/var/www/html
        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.使用DB创建一个新的NextCloud Docker-Compose文件

将以下信息复制到compose文件中

version: '3'

volumes:
    letsencrypt:
    nextcloud:

services: 
    proxy:
        image: staticfloat/nginx-certbot
        ports:
            - 80:80
            - 443:443
        environment: 
            CERTBOT_EMAIL: [email protected].com
            ENVSUBST_VARS: FQDN
            FQDN: nextcloud.51sec.org
        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[email protected]
            - MYSQL_PASSWORD[email protected]
            - 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


您可能希望使用自己的设置更改以下配置:

            CERTBOT_EMAIL: [email protected].com
            ENVSUBST_VARS: FQDN
            FQDN: nextcloud.51sec.org
           - MYSQL_ROOT_PASSWORD[email protected]
            - MYSQL_PASSWORD[email protected]
            - MYSQL_DATABASE=nextcloud
            - MYSQL_USER=nextcloud
请确保为NextCloud.51Sec.org创建了DNS记录,该记录指向此虚拟机's public ip.

请确保您的防火墙端口80和443在云安全组和本地虚拟机上打开。默认情况下,ubuntu18.04 UFW状态无效。

确认所有配置都有Ben Set正确,您可以使用docker-compose命令启动您的Docker:

cd /opt/nextcloud
docker-compose up -d


Using your Browser to connect to the domain url, in my case, it is  //nextcloud.fabiandinkins.com







安装后


安装后,有几件事要清理并进一步配置。

1  安装dockerwe将不得不运行以下两个命令来修复设置警告:

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用户是Admin,则要在此用户下添加本地文件,则需要将所有文件复制到以下文件夹。
/opt/nextcloud/app/data/admin/files

将所有文件复制到此文件夹中,使用以下命令扫描它们:

docker-compose exec -u www-data app php occ files:scan --all

3  如果要安装ffmpeg,请按照以下命令:

docker exec -it nextcloud_app_1 bash
apt -y update
apt -y install ffmpeg



备份& Restore

以下是备份和恢复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 [email protected]:/opt
4  在新机器上安装Docker和Docker撰写
cd /opt
tar -xzvf nextcloud.tar.gz

5 带来Dockers Up,它仍应保留所有文件和配置

cd nextcloud
docker-compose up -d



YouTube:




参考










5评论:

  1. 谢谢,我刚刚设法在raspberry pi 4b上设置它。建议:从nginx config中删除http2,以增强上传速度。

    回复删除
    答案
    1. 你为你的pi 4安装了什么图像?我没有'到目前为止,迄今为止有任何运气。我的数据库似乎正在工作。 NextCloud映像日志显示一些错误,但我没有'T可以访问界面以测试它。

      删除
  2. 请你这么善良,让我知道如何从mystic.com配置nginx来加载mystic.com/nexcloud view?提前发了很多!

    回复删除
  3. 请你这么善良,让我知道如何从mystic.com配置nginx来加载mystic.com/nexcloud view?提前发了很多!

    回复删除
  4. 请你这么善良,让我知道如何从mystic.com配置nginx来加载mystic.com/nexcloud view?提前发了很多!

    回复删除