​ 最近部署nextcloud的时候,老是在最后一步遇到ERR_TOO_MANY_REDIRECTS这个问题,搜了下网上这个问题存在已久,而且现在很多人还会遇到,原因也是说不清,大多是说因为PHP版本的问题,PHP我是从7.0 7.1 7.2换了个遍,抛弃MySQL使用内置的SQLlite都无济于事,实在没辙,最终只能选择docker安装。

​ 而且又因为caddy出了很奇怪的错误,无法启动,索性直接nginx走起。

环境

  • CentOS 7.6.1810
  • Docker 18.09.0
  • Nginx 1.12.2-2.el7.x86_64

1.部署Docker环境

详细教程参照:https://spex.top/archives/docker-docker-compose.html


2.部署Nextcloud

2.1 docker-compose.yml

为了便于管理,我们将把nextcloud的yml文件新建文件夹进行操作。

# 新建文件夹与文件
mkdir -p /wwwdata/docker/nextcloud
cd /wwwdata/docker/nextcloud
touch docker-compose.yml
# docker-compose.yml 配置,这里我们将nextcloud端口映射至2500上。
version: '3'

networks:
  nextcloud_network:
    external: false

services:
  nextcloud:
    image: wonderfall/nextcloud
    depends_on:
      - nextcloud-db           # If using MySQL
      - solr                   # If using Nextant
      - redis                  # If using Redis
    environment:
      - UID=1000
      - GID=1000
      - UPLOAD_MAX_SIZE=10G
      - APC_SHM_SIZE=128M
      - OPCACHE_MEM_SIZE=128
      - CRON_PERIOD=15m
      - TZ=Asia/Shanghai
      - ADMIN_USER=admin            # Don't set to configure through browser
      - ADMIN_PASSWORD=admin        # Don't set to configure through browser
      - DOMAIN=localhost
      - DB_TYPE=mysql
      - DB_NAME=nextcloud
      - DB_USER=nextcloud
      - DB_PASSWORD=nextcloud
      - DB_HOST=nextcloud-db
    volumes:
      - /data/docker/nextcloud/data:/data
      - /data/docker/nextcloud/config:/config
      - /data/docker/nextcloud/apps:/apps2
      - /data/docker/nextcloud/themes:/nextcloud/themes
    networks:
      - nextcloud_network
    ports:
      - "2500:8888"

  # If using MySQL
  nextcloud-db:
    image: mariadb:10
    volumes:
      - /data/docker/nextcloud/db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=nextcloud
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=nextcloud
    networks:
      - nextcloud_network

  # If using Nextant
  solr:
    image: solr:6-alpine
    container_name: solr
    volumes:
      - /data/docker/nextcloud/solr:/opt/solr/server/solr/mycores
    entrypoint:
      - docker-entrypoint.sh
      - solr-precreate
      - nextant
    networks:
      - nextcloud_network
    ports:
      - "8983:8983"

  # If using Redis
  redis:
    image: redis:alpine
    container_name: redis
    volumes:
      - /data/docker/nextcloud/redis:/data
    networks:
      - nextcloud_network

2.2 启动与自启动

# 启动nextcloud.yml
docker-compose up -d
# 配置nextcloud开机自启动
vi /etc/rc.d/rc.local

docker-compose -f /wwwdata/docker/nextcloud/docker-compose.yml up -d

chmod +x /etc/rc.d/rc.local

2.3 踩坑

  • OCI runtime create failed: unable to retrieve OCI runtime error (open /run/docker/containerd/daemon/io.containerd.runtime.v1.linux/moby/9b29552e6d78ece7b9bf9ac33e239e1e2839cf0a50908030af5b9432495fa952/log.json: no such file or directory): runc did not terminate sucessfully: unknown

解决方式:如果运行docker-compose up -d出现这个问题,则CentOS版本不对,不支持7.2,请升级至更高版本,7.4以上。

3.配置Nginx反向代理


3.1 安装Nginx

# 安装epel仓库
yum install -y epel-release

# 安装nginx
yum install -y nginx

# 配置Nginx启动与开机自启动
systemctl enable nginx && systemctl start nginx

3.2 Nextcloud.conf配置文件

默认的路径/etc/nginx/conf.d/nextcloud.conf

upstream nextcloud {
    server 127.0.0.1:2500;
}

server {
    listen 80;
    server_name pan.jun-yuan.com;

    rewrite ^(.*)$ https://$host$1 permanent;
}

server {
    listen          443;
    server_name     pan.jun-yuan.com;
    index           index.html index.htm index.php;
 
    ssl on;
    ssl_certificate /etc/nginx/ssl/pan/fullchain.cer;
    ssl_certificate_key /etc/nginx/ssl/pan/pan.jun-yuan.com.key;
    ssl_session_timeout 5m;
    ssl_session_cache shared:SSL:20m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers   on;
 
    location / {
      proxy_pass http://nextcloud;
      proxy_set_header Host $http_host;
      proxy_set_header X-Forwarded-Proto $scheme;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header Upgrade $http_upgrade; 
      proxy_set_header Connection $connection_upgrade;
      proxy_pass_header Set-Cookie;
      proxy_pass_header X-CSRF-TOKEN;
}
    
    location = /.well-known/carddav {
        return 301 $scheme://$host/remote.php/dav;
    }

    location = /.well-known/caldav {
        return 301 $scheme://$host/remote.php/dav;
    }

3.2 相关

在配置反向代理的时候遇到了很多问题,具体可以查看:https://spex.top/archives/nginx-problem.html
关于SSL证书的申请与管理具体可以查看:https://spex.top/archives/acme-ssl-https.html

至此我们的nextcloud已经可以正常使用。

4.配置插件

待更新


5.使用

使用nextcloud的一些操作。

5.1 批量导入文件

基于Docker的Nextcloud利用OCC批量导入文件:https://spex.top/archives/docker-nextcloud-occ-filescan.html


5.2 修改新用户默认文件

修改基于Docker的Nextcloud新用户默认文件:https://spex.top/archives/docker-nextcloud-change-skeleton-file.html


Last modification:May 7th, 2019 at 03:15 pm