美文网首页docker
docker nextcloud

docker nextcloud

作者: 胸口砕大石 | 来源:发表于2019-10-12 15:13 被阅读0次

    背景

    百度云小电影总被和谐,所以私有云很重要

    普通版本

    已有数据库
    $ docker run -d --restart=always -p 80:80 -p 443:443 -v /home/nextcloud:/var/www/html --name nextcloud nextcloud
    

    compose版本

    参考kernycai的文章,传送门https://www.jianshu.com/p/94890cfa6240,大神的是阿里云OSS版本,我的是本地磁盘,因为穷

    安装compose
    $ yum -y install epel-release
    $ yum -y install python-pip
    $ pip install --upgrade --force-reinstall pip==9.0.3 // 这里如果升级最新的,比如 10.0 以上的,下面安装 docker-compose 会报错
    $ pip install docker-compose
    $ docker-compose --version
    
    编写nginx配置文件

    目录结构


    image.png
    upstream php-handler {
    server app:9000;
    #server unix:/var/run/php5-fpm.sock;
    }
    server {
        listen 80;
        server_name IP或者域名(需要替换);
        # enforce https
        return 301 https://$server_name$request_uri;
    }
    server {
        listen 443 ssl;
        server_name IP或者域名(需要替换);
        ssl_certificate /etc/nginx/cert/servhostname.local.crt;
        ssl_certificate_key /etc/nginx/cert/servhostname.local.key;
        # Add headers to serve security related headers
        # Before enabling Strict-Transport-Security headers please read into this
        # topic first.
        add_header Strict-Transport-Security "max-age=15768000;
        includeSubDomains; preload;";
        add_header X-Content-Type-Options nosniff;
        add_header X-Frame-Options "SAMEORIGIN";
        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;
        # Path to the root of your installation
        root /var/www/html/;
        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }
        # The following 2 rules are only needed for the user_webfinger app.
        # Uncomment it if you're planning to use this app.
        #rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
        #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
        # last;
        location = /.well-known/carddav {
          return 301 $scheme://$host/remote.php/dav;
        }
        location = /.well-known/caldav {
          return 301 $scheme://$host/remote.php/dav;
        }
        # set max upload size
        client_max_body_size 10G;
        fastcgi_buffers 64 4K;
        # Disable gzip to avoid the removal of the ETag header
        gzip off;
        # Uncomment if your server is build with the ngx_pagespeed module
        # This module is currently not supported.
        #pagespeed off;
        error_page 403 /core/templates/403.php;
        error_page 404 /core/templates/404.php;
        location / {
            rewrite ^ /index.php$uri;
        }
        location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
            deny all;
        }
        location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
            deny all;
        }
        location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.php(?:$|/) {
            include fastcgi_params;
            fastcgi_split_path_info ^(.+\.php)(/.*)$;
            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;
        }
        # Adding the cache control header for js and css files
        # Make sure it is BELOW the PHP block
        location ~* \.(?:css|js)$ {
            try_files $uri /index.php$uri$is_args$args;
            add_header Cache-Control "public, max-age=7200";
            # Add headers to serve security related headers (It is intended to
            # have those duplicated to the ones above)
            # Before enabling Strict-Transport-Security headers please read into
            # this topic first.
            add_header Strict-Transport-Security "max-age=15768000;
            includeSubDomains; preload;";
            add_header X-Content-Type-Options nosniff;
            add_header X-Frame-Options "SAMEORIGIN";
            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;
            # Optional: Don't log access to assets
            access_log off;
        }
        location ~* \.(?:svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$ {
            try_files $uri /index.php$uri$is_args$args;
            # Optional: Don't log access to other assets
            access_log off;
        }
    }
    
    
    编写compose文件
    image.png
    version: '2'
    
    volumes:
      app:
      db:
      nginx:
      omgwtfssl:
    
    networks:
      proxy-tier:
    
    services:
      db:
        container_name: cloud_db
        image: mariadb
        restart: always
        volumes:
          - /home/docker_nextcloud/db:/var/lib/mysql
        environment:
          - MYSQL_ROOT_PASSWORD=root
          - MYSQL_DATABASE=nextcloud
    
      app:
        container_name: cloud_app
        image: nextcloud:fpm
        links:
          - db
        volumes:
          - /home/docker_nextcloud/nextcloud:/var/www/html/
        restart: always
       
      nginx:
        container_name: cloud_web
        image: nginx
        ports:
          - 80:80
          - 443:443
        links:
          - app
        volumes:
          - /home/docker_nextcloud/nextcloud:/var/www/html/
          - /home/docker_nextcloud/nginx/conf.d:/etc/nginx/conf.d/
          - /home/docker_nextcloud/nginx/cert:/etc/nginx/cert/
        restart: always
    
      omgwtfssl:
        image: paulczar/omgwtfssl
        restart: "no"
        volumes:
          - /home/docker_nextcloud/nginx/cert:/certs
        environment:
          - SSL_SUBJECT=servhostname.local
          - CA_SUBJECT=57134898@qq.com
          - SSL_KEY=/certs/servhostname.local.key
          - SSL_CSR=/certs/servhostname.local.csr
          - SSL_CERT=/certs/servhostname.local.crt
        networks:
          - proxy-tier
    

    nextcloud页面初次打开进行配置的时候,数据库的主机名称填写的是compose文件内的配置,是db。基本了解点docker的人都清楚这点,这里记录下,免得大意给忘掉。
    ssl是自建的证书,所以会有提示证书不安全。如果自己拿域名去申请正式证书的话,就不会有这种问题。

    启动

    docker-compose up -d
    

    等待拉取镜像后输入 IP或者域名进入页面
    域名需要加入config.php的trusted_domains节点中,不加的话网页上会有提示


    image.png
    image.png

    相关文章

      网友评论

        本文标题:docker nextcloud

        本文链接:https://www.haomeiwen.com/subject/phqxmctx.html