D

Docker Nextcloud 部署

Bejix 代码笔记 2024-04-03

Docker Nextcloud 部署

docker-compose.yml

version: '2.1'

services:
  nextcloud:
    image: nextcloud
    container_name: nextcloud
    hostname: nextcloud
    volumes:
      - /home/app/nextcloud/data:/var/www/html
    networks:
      - nextcloud_default
    depends_on:
      - redis
    restart: always
    links:
      - mysql:mysql
      - onlyoffice:onlyoffice
      - redis:redis

  mysql:
    image: mysql
    container_name: mysql
    hostname: mysql
    environment:
      - TZ=Asia/Shanghai
      - MYSQL_ROOT_PASSWORD=root@
    volumes:
      - /home/app/mysql/data:/var/lib/mysql
      - /home/app/mysql/config:/etc/mysql/conf.d
    networks:
      - nextcloud_default
    restart: always

  onlyoffice:
    image: onlyoffice/documentserver
    container_name: onlyoffice
    hostname: onlyoffice
    restart: always
    ports:
      - 9000:80
      - 9001:443
    environment:
      - REDIS_SERVER_HOST=redis
      - REDIS_SERVER_PORT=6379
    volumes:
      - /home/app/onlyoffice/logs:/var/log/onlyoffice
      - /home/app/onlyoffice/data:/var/www/onlyoffice/data
    networks:
      - nextcloud_default

  redis:
    image: redis
    hostname: redis
    container_name: redis
    volumes:
      - /home/app/redis/data:/data
      - /home/app/redis/conf:/etc/redis/redis.conf
    restart: always
    networks:
      - nextcloud_default

  nginx:
    image: nginx
    container_name: nginx
    hostname: nginx
    restart: always
    ports:
      - 80:80
      - 443:443
    volumes:
      - /home/app/nginx/conf:/etc/nginx/conf.d
      - /home/app/nginx/certs:/etc/nginx/certs
    networks:
      - nextcloud_default

networks:
  nextcloud_default:
    external: true
    name: nextcloud_default

Nginx 配置

server {
    listen 80;
    listen [::]:80;
    server_name _;
    return 301 https://$host$request_uri;
}

server {

    listen 443 ssl;
    listen [::]:443 ssl;
    server_name _;
    http2 on;

    ssl_certificate /etc/nginx/certs/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/privkey.pem;

    client_max_body_size 10G;

    proxy_connect_timeout 600s;
    proxy_send_timeout 600s;
    proxy_read_timeout 600s;

    proxy_buffering off;
    proxy_request_buffering off;
    proxy_http_version 1.1;
    chunked_transfer_encoding on;

    add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;" always;

    location / {
        proxy_pass http://nextcloud;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    rewrite /.well-known/carddav /remote.php/dav permanent;
    rewrite /.well-known/caldav /remote.php/dav permanent;

    location /socket.io {
        proxy_pass http://onlyoffice/socket.io;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }
}

启动

docker-compose up # 前台启动
docker-compose up -d # 后台启动

数据库操作

进入mysql docker 容器

docker exce -it mysql bash

链接数据库

mysql -uroot -proot@

创建数据库

CREATE USER 'nextcloud'@'%' IDENTIFIED BY 'nextcloud@pwd';
CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextcloud'@'%';
flush privileges;
## 查看数据库与user是否创建
show databases;
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
PREV
第一台小玩具(小主机)-零刻GTR7
NEXT
go-redis 快速入门教程

评论(0)

发布评论