본문 바로가기
서버 및 보안

ownCloud

by 다움위키 2023. 12. 25.

ownCloud파일 호스팅 서비스를 만들고 사용하기 위한 클라이언트-서버 소프트웨어의 모음입니다. ownCloud는 기능적으로 널리 사용되는 Dropbox와 유사합니다. ownCloud와 Dropbox의 주요 기능적 차이점은 ownCloud는 주로 서버 소프트웨어라는 것입니다. (회사의 ownCloud.online은 호스팅 서비스입니다.) ownCloud의 서버 버전은 자유와 오픈-소스이고, 따라서 누구나 자신의 개인 서버에 무료로 설치하고 운영할 수 있습니다.

ownCloud는 온라인 오피스 제품군 문서 편집, 캘린더 및 연락처 동기화, 등을 통해 구글 드라이브처럼 작동할 수 있는 확장 프로그램을 지원합니다. 그것의 개방성은 서버의 물리적 기능에 의해 결정되는 엄격한 제한 (예를 들어 저장 공간 또는 사용자 수)을 갖는 대신 저장 공간 또는 연결된 클라이언트 수에 대한 강제 할당을 피합니다.

전제 조건

Owncloud의 모든 기능을 사용하기 위해서는 다음이 설치되어 있어야 합니다:

  • LEMP 스택 - (Linux-Nginx-Mariadb-Php) : 컴퓨터에 리눅스 운영체제를 설치하고 웹서버, 데이터베이스 서버, 웹 스크립트 언어가 적절히 연동되도록 설치 및 설정을 먼저 해야 합니다.
  • Php 필수 모듈 : ctype, dom, GD, iconv, JSON, libxml, mb multibyte, posix, SimpleXML, XMLWriter, zip, zlib
  • Php 추천 모듈 : curl, fileinfo, bz2, intl, mcrypt, openssl
  • SSL 인증서 : FQDN이 없을 때에는 자체-서명된 SSL 인증서를 생성해야 합니다.

설치(Php-7.0 사용)

아직 우분투 공식 저장소에는 패키지가 없지만, 개발자들이 배포판을 위한 전용 저장소를 제공합니다. 저장소에 접근하기 위한 열쇠를 가져와서 키 목록에 추가를 합니다.

저장소 키를 사용하여 패키지를 받기 위해서 키에 대한 서버 목록을 추가합니다.

이제 목록을 판올림하고 해당 패키지를 설치합니다.

  • sudo apt-get update
  • sudo apt-get install owncloud
이후의 과정은 php7.0을 설치한 후에 작성할 예정입니다. 미리 해 보실 분들은 아래의 과정을 참고하셔서 진행하시기 바랍니다.

설치(PHP5.6 사용)

PHP 모듈 설치

먼저 Php overlay를 설정하시고 아래의 패키지를 설치합니다.

  • sudo apt-get install php5.6-gd php5.6-json php5.6-mysql php5.6-curl php5.6-intl php5.6-mcrypt php5.6-imagick

Owncloud의 기능을 완전히 사용하기 위해서는 아래의 모듈도 같이 설치합니다.

  • sudo apt-get install php5.6-bz2 php5.6-gd php5.6-mbstring php5.6-xml php5.6-zip

새 모듈을 적용하기 위해서 php5.6-fpm을 재시작합니다.

  • sudo systemctl restart php5.6-fpm

데이터베이스 생성

Owncloud에 사용될 데이터베이스와 사용자 및 사용자 암호를 만들어 줍니다.

  • sudo mysql -u root -p
MariaDB [(none)]> CREATE DATABASE owncloud;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON owncloud.* TO owncloud@localhost IDENTIFIED BY 'your_password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

owncloud 설치

최신판을 내려받아서 gpg 서명을 확인합니다.

gpg: Signature made 2016년 09월 20일 (화)  using RSA key ID F6978A26
gpg: Good signature from "ownCloud <info@owncloud.com>"
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: E303 6906 AD9F 3080 7351  FAC3 2D5D 5E97 F697 8A26

정상적으로 확인이 되면 서명 파일을 제거하고 설치 파일을 풀어 줍니다.

  • sudo rm owncloud.asc owncloud-9.1.1.tar.bz2.asc
  • sudo tar jxvf owncloud-9.1.1.tar.bz2

설치를 위해서 접근 권한을 수정합니다.

  • sudo chown -R www-data:www-data /var/www/html/owncloud/

Nginx 설정

웹 서버의 설정을 아래와 같이 만듭니다. /etc/nginx/site-available/owncloud에 씁니다.

server {
    listen 4000;
    server_name your_domain;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    root /var/www/html/owncloud;

    location / {
        index index.php;
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php5.6-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

설정을 사용하도록 심볼릭 링크를 하고 테스트를 합니다.

  • cd /etc/nginx/site-enabled
  • sudo ln -sf /etc/nginx/site-available/owncloud .
  • sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

정상적으로 테스트가 끝났으므로 기동을 합니다.

  • sudo systemctl restart nginx}}

이제 설치 마무리를 위해서 http://localhost:4000 으로 접근을 합니다.

ownCloud in the webroot of nginx

좀 더 자세한 설정을 하고 싶다면 홈페이지 설치 문서에 나와 있는 내용으로 변경해서 사용해 봅니다. Nginx의 webroot로 사용하는 경우입니다. /etc/nginx/site-available/owncloud에 씁니다.

upstream php-handler {
    server unix:/var/run/php/php5.6-fpm.sock;
}

server {
    listen 4000;
    server_name cloud.example.com;

    # 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=15552000; includeSubDomains";
    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/owncloud/;

    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;
    }

    location /.well-known/acme-challenge { }

    # set max upload size
    client_max_body_size 512M;
    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$is_args$args;
    }

    location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
        return 404;
    }
    location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
        return 404;
    }

    location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.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;
        fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
        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 $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=15552000; includeSubDomains";
        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;
    }
}

이 경우에는 http://localhost:4000 으로 접근을 해야 합니다. 현재는 ssl은 사용하지 않도록 설정해 두었습니다. 추후에 ssl을 사용하게 되면 홈페이지에서 제공하는 설정을 사용해야 합니다.

갤러리 파일을 로딩을 오래합니다. 최종적으로 완료되는지 확인을 못했습니다. 추후에 새롭게 설치해서 확인을 해야 합니다.

ownCloud in a subdir of nginx

Nginx내부의 subdir로 설정하는 방법입니다. /etc/nginx/site-available/owncloud에 씁니다.

upstream php-handler {
    #server 127.0.0.1:9000;
    server unix:/var/run/php/php5.6-fpm.sock;
}

server {
    listen 4000;
    server_name cloud.example.com;

    # 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=15552000; includeSubDomains";
    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 /owncloud/public.php?service=host-meta last;
    #rewrite ^/.well-known/host-meta.json /owncloud/public.php?service=host-meta-json last;

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

    location /.well-known/acme-challenge { }

    location ^~ /owncloud {

        # set max upload size
        client_max_body_size 512M;
        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 /owncloud/core/templates/403.php;
        error_page 404 /owncloud/core/templates/404.php;

        location /owncloud {
            rewrite ^ /owncloud/index.php$uri;
        }

        location ~ ^/owncloud/(?:build|tests|config|lib|3rdparty|templates|data)/ {
            return 404;
        }
        location ~ ^/owncloud/(?:\.|autotest|occ|issue|indie|db_|console) {
            return 404;
        }

        location ~ ^/owncloud/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+|core/templates/40[34])\.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;
            fastcgi_param modHeadersAvailable true; #Avoid sending the security headers twice
            fastcgi_param front_controller_active true;
            fastcgi_pass php-handler;
            fastcgi_intercept_errors on;
            fastcgi_request_buffering off;
        }

        location ~ ^/owncloud/(?:updater|ocs-provider)(?:$|/) {
            try_files $uri $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 /owncloud/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=15552000; includeSubDomains";
            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 /owncloud/index.php$uri$is_args$args;
            # Optional: Don't log access to other assets
            access_log off;
        }
    }
}

이 경우에는 http://localhost:4000/owncloud 로 접근을 해야 합니다. 현재는 ssl을 사용하지 않도록 설정을 해 두었습니다. 추후에 ssl을 사용하게 되면 홈페이지에서 제공하는 설정으로 복구를 해야 합니다.

접근 권한

위에서 입력한 값을 정확히 넣어도 필요한 디렉토리가 없어서 설치가 이루어지지 않습니다. 그래서 필요한 디렉토리을 만들고 접근 권한을 설정하기 위해서 스크립트 파일을 만듭니다. ~/owncloud.permissions에 씁니다.

#!/bin/bash
ocpath='/var/www/html/owncloud'
htuser='www-data'
htgroup='www-data'
rootuser='root'

printf "Creating possible missing Directories\n"
mkdir -p $ocpath/data
mkdir -p $ocpath/assets
mkdir -p $ocpath/updater

printf "chmod Files and Directories\n"
find ${ocpath}/ -type f -print0 | xargs -0 chmod 0640
find ${ocpath}/ -type d -print0 | xargs -0 chmod 0750

printf "chown Directories\n"
chown -R ${rootuser}:${htgroup} ${ocpath}/
chown -R ${htuser}:${htgroup} ${ocpath}/apps/
chown -R ${htuser}:${htgroup} ${ocpath}/assets/
chown -R ${htuser}:${htgroup} ${ocpath}/config/
chown -R ${htuser}:${htgroup} ${ocpath}/data/
chown -R ${htuser}:${htgroup} ${ocpath}/themes/
chown -R ${htuser}:${htgroup} ${ocpath}/updater/

chmod +x ${ocpath}/occ

printf "chmod/chown .htaccess\n"
if [ -f ${ocpath}/.htaccess ]
 then
  chmod 0644 ${ocpath}/.htaccess
  chown ${rootuser}:${htgroup} ${ocpath}/.htaccess
fi
if [ -f ${ocpath}/data/.htaccess ]
 then
  chmod 0644 ${ocpath}/data/.htaccess
  chown ${rootuser}:${htgroup} ${ocpath}/data/.htaccess
fi

파일에 실행 모드를 추가하고 실행을 합니다.

  • cd
  • chmod +x owncloud.permissions
  • sudo ./owncloud.permissions}}

다시 http://localhost:4000 으로 접근을 하셔서 설치를 마무리합니다.

Security & setup warnings

처음 접속 후에 관리자 계정으로 접근하시면 보안이나 다른 프로그램과의 연동에 필요한 파일이 없다는 사실을 알려줍니다.

PHP 설정

PHP 환경 변수가 제대로 설정이 되지 않아서 아래의 경고가 발생합니다.

php does not seem to be setup properly to query system environment variables. The test with getenv("PATH") only returns an empty response.

/etc/php/5.6/fpm/pool.d/www.conf에 씁니다.

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

PHP를 재기동하고 확인을 합니다.

  • sudo systemctl restart php5.6-fpm

WebDAV 설정

WebDAV 설정이 되지 않아서 아래의 오류가 발생합니다.

Your web server is not yet set up properly to allow file synchronization because the WebDAV interface seems to be broken.

Performance Tweaks

캐싱에 사용될 수 있는 것은 apcu, memcached, redis의 세 가지 정도입니다. 여기서 local은 apcu가 적당하다고 합니다. 나머지는 redis가 하는 것이 좋다고 합니다. 그러나 apcu는 현재 php5.6에서 동작하는 패키지가 없습니다. 추후에 자체 제작해야 할 것으로 보입니다.

  • sudo apt-get install redis-server php5.6-redis

Redis 서비스를 시작하고 잘 작동하는지 확인합니다.

  • sudo systemctl start redis
  • sudo systemctl enable redis
  • ps ax | grep redis

22203 ? Ssl 0:00 /usr/bin/redis-server 127.0.0.1:6379

이제 owncloud의 설정을 추가합니다. /var/www/html/owncloud/config/config.php에 씁니다.

...
  'installed' => true,
  'filelocking.enabled' => true,
  'memcache.distributed' => '\OC\Memcache\Redis',
  'memcache.locking' => '\OC\Memcache\Redis',
  'memcache.local' => '\OC\Memcache\Redis',
  'redis' => array(
     'host' => 'localhost',
     'port' => 6379,
  ),
);

Php-5.6-fpm과 nginx 서비스를 새로 시작한 후에 http://localhost:4000/owncloud/settings/admin 로 접근해 봅니다.

설치 재시작

아직 사용법을 잘 모르는 상황에서 중간에 무엇인가 꼬여서 해법을 찾을 수 없을 때에는 처음부터 새롭게 설치해 볼 수 있습니다. 먼저 웹 문서를 삭제하고 새롭게 풉니다.

  • cd /var/www/html/
  • sudo rm -rf owncloud
  • sudo tar jxvf owncloud-9.1.1.tar.bz2}}

만들어졌던 데이터베이스를 지우고 새롭게 만듭니다.

  • sudo mysql -u root -p
MariaDB [(none)]> DROP DATABASE owncloud;
MariaDB [(none)]> CREATE DATABASE owncloud;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON owncloud.* TO owncloud@localhost IDENTIFIED BY 'your_password';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

http://localhost:4000/owncloud 로 접근해서 초기 설정을 합니다.

HTTPS 설정

SSL 인증서 만들기

  • cd /etc/ssl
  • sudo openssl req -config /etc/ssl/openssl.cnf -x509 -days 3650 -batch -nodes -newkey rsa:2048 -keyout private/cloud.example.com.key -out certs/cloud.example.com.crt
Generating a 2048 bit RSA private key
................................................................................................................+++
...+++
writing new private key to 'private/cloud.example.com.key'
-----

nginx 설정 수정

/etc/nginx/site-available/owncloud을 수정합니다.

server {
    listen 4000;
    server_name cloud.example.com;
    # enforce https
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name cloud.example.com;

    ssl_certificate /etc/ssl/certs/cloud.example.com.crt;
    ssl_certificate_key /etc/ssl/private/cloud.example.com.key;
...
    add_header Strict-Transport-Security "max-age=15552000; includeSubDomains";
...
            fastcgi_param HTTPS on;
...

이렇게 설정하고 오류가 생기는 경우는 아래의 파일에서 port번호를 보고 적당히 지우고 재 접근합니다. /var/www/html/owncloud/config/config.php에 씁니다.

  'trusted_domains' =>
  array (
    0 => 'cloud.example.com',
  ),
  'datadirectory' => '/var/www/html/owncloud/data',
  'overwrite.cli.url' => 'http://cloud.example.com/owncloud',

Ubuntu Desktop Client

우분투에서 사용할 수 있는 클라이언트를 내려받고 판올림이 되는 것들은 자동으로 받기위해서 키를 등록합니다.

External resources