Nextcloud+collabora online实现在线文档编辑

将编辑好的文件复制到nginx容器中

环境:

CentOS 8.5.2111

更换yum源为阿里云


rm -rf /etc/yum.repos.d/*
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
yum install -y yum-utils

安装Docker


yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install docker-ce docker-ce-cli containerd.io

启动Docker

sudo systemctl start docker

pull下来需要的镜像


docker pull collabora/code:21.11.2.3.1
docker pull mysql:8.0.29
docker pull php:7.4.29-fpm
docker pull nginx:stable

创建collabora/code容器并安装中文字体


docker run --name office -v 中文字体路径:/usr/share/fonts/chinese -e "domain=nextcloud域名" -e "username=admin" -e "password=123456" --restart always --cap-add MKNOD collabora/code:21.11.2.4.1
docker exec -ti -u root office bash

进入容器环镜后执行同步中文字体到 collaboraoffice


coolwsd-systemplate-setup /opt/cool/systemplate /opt/collaboraoffice

创建nginx 和php-fpm容器环境


docker run --name nginx -v /var/www/html:/var/www/html -d nginx:stable
docker run --name fpm74 -v /var/www/html:/var/www/html -w /var/www/html -d php:7.4.29-fpm

配置php-fpm


docker cp fpm:/usr/local/etc/php-fpm.d/www.conf www.conf

对复制出来的文件进行编辑


php_admin_value[memory_limit] = 512M
docker cp www.conf fpm:/usr/local/etc/php-fpm.d/www.conf

配置nginx
创建nextcloud的nginx配置文件 并录入内容

upstream php-handler {
    server fpm74:9000;
}
server {
    listen 443 ssl http2;
    server_name office.seebu.com;
    server_tokens off;
    ssl_certificate     /etc/nginx/conf.d/certs/office.pem;
    ssl_certificate_key /etc/nginx/conf.d/certs/office.key;
    location ^~ /browser {
       proxy_pass https://office:9980;
       proxy_set_header Host $http_host;
   }
   location ^~ /hosting/discovery {
       proxy_pass https://office:9980;
       proxy_set_header Host $http_host;
   }
   location ^~ /hosting/capabilities {
       proxy_pass https://office:9980;
       proxy_set_header Host $http_host;
   }
   location ~ ^/cool/(.*)/ws$ {
       proxy_pass https://office:9980;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "Upgrade";
       proxy_set_header Host $http_host;
       proxy_read_timeout 36000s;
   }
   location ~ ^/(c|l)ool {
       proxy_pass https://office:9980;
       proxy_set_header Host $http_host;
   }
   location ^~ /cool/adminws {
       proxy_pass https://office:9980;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "Upgrade";
       proxy_set_header Host $http_host;
       proxy_read_timeout 36000s;
   }
}
map $arg_v $asset_immutable {
    "" "";
    default "immutable";
}
server {
    listen 80;
    listen [::]:80;
    server_name nextcloud;
    server_tokens off;
    return 301 https://$server_name$request_uri;
}
server {
    listen 443      ssl http2;
    listen [::]:443 ssl http2;
    server_name nextcloud;
    root /var/www/html/nextcloud;

    ssl_certificate     /etc/nginx/conf.d/certs/nextcloud.pem;
    ssl_certificate_key /etc/nginx/conf.d/certs/nextcloud.key;
    server_tokens off;
    client_max_body_size 512M;
    client_body_timeout 300s;
    fastcgi_buffers 64 4K;
    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/wasm 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;
    add_header Referrer-Policy                      "no-referrer"   always;
    add_header X-Content-Type-Options               "nosniff"       always;
    add_header X-Download-Options                   "noopen"        always;
    add_header X-Frame-Options                      "SAMEORIGIN"    always;
    add_header X-Permitted-Cross-Domain-Policies    "none"          always;
    add_header X-Robots-Tag                         "none"          always;
    add_header X-XSS-Protection                     "1; mode=block" always;
    fastcgi_hide_header X-Powered-By;
    index index.php index.html /index.php$request_uri;
    location = / {
        if ( $http_user_agent ~ ^DavClnt ) {
            return 302 /remote.php/webdav/$is_args$args;
        }
    }
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    location ^~ /.well-known {
        location = /.well-known/carddav { return 301 /remote.php/dav/; }
        location = /.well-known/caldav  { return 301 /remote.php/dav/; }
        location /.well-known/acme-challenge    { try_files $uri $uri/ =404; }
        location /.well-known/pki-validation    { try_files $uri $uri/ =404; }
        return 301 /index.php$request_uri;
    }
    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)(?:$|/)  { return 404; }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console)                { return 404; }
    location ~ \.php(?:$|/) {
        rewrite ^/(?!index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+|.+\/richdocumentscode\/proxy) /index.php$request_uri;
        fastcgi_split_path_info ^(.+?\.php)(/.*)$;
        set $path_info $fastcgi_path_info;
        try_files $fastcgi_script_name =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param HTTPS on;
        fastcgi_param modHeadersAvailable true;         # Avoid sending the security headers twice
        fastcgi_param front_controller_active true;     # Enable pretty urls
        fastcgi_pass php-handler;
        fastcgi_intercept_errors on;
        fastcgi_request_buffering off;
        fastcgi_max_temp_file_size 0;
    }
    location ~ \.(?:css|js|svg|gif|png|jpg|ico|wasm|tflite|map)$ {
        try_files $uri /index.php$request_uri;
        add_header Cache-Control "public, max-age=15778463, $asset_immutable";
        access_log off;     # Optional: Don't log access to assets
        location ~ \.wasm$ {
            default_type application/wasm;
        }
    }
    location ~ \.woff2?$ {
        try_files $uri /index.php$request_uri;
        expires 7d;         # Cache-Control policy borrowed from `.htaccess`
        access_log off;     # Optional: Don't log access to assets
    }
    location /remote {
        return 301 /remote.php$request_uri;
    }
    location / {
        try_files $uri $uri/ /index.php$request_uri;
    }
}

将编辑好的配置文件复制进nginx容器

code>docker nextcloud.conf nginx:/etc/nginx/conf.d/

下载Nextcloud代码

curl -O https://download.nextcloud.com/server/releases/nextcloud-23.0.4.zip
unzip nextcloud-23.0.4.zip
mv nextcloud-23.0.4 /var/www/html/nextcloud

重启Nginx、PHP-FPM 。
完工。

2年 ago