👤
Novice Handbook
  • Novice Handbook
  • Guide
  • Internet และ Web
    • HTML
  • Computer Language
    • Basic Computer Language (LV.1)
    • C Language (LV.1)
    • Python3 (LV.1)
  • Operating System
    • Linux
      • Basic Linux (LV.1)
  • TOOLS
    • Text Editor
      • Vim Editor
    • Source Control
      • GitLab
        • GitLab for small site (LV.1)
    • Container
      • Docker
        • Docker (LV.1)
        • Docker (LV.2)
      • Kubernetes
        • Kubernetes Intro (LV.0)
        • Kubernetes Basic (LV.1)
        • Kubernetes Intermediate (LV.2)
        • Helm (LV.2)
        • RKE2 (LV.3)
        • K3S (LV.3)
        • K3D (LV.3)
    • Repository
      • Harbor
        • Harbor for small site (LV.1)
        • Harbor for enterprise (LV.2)
    • Database
      • Redis
        • Redis on Docker Compose (LV.1)
        • Redis on Kubernetes (LV.2)
      • Elastic Stack
        • Elasticsearch & Kibana for small site (LV.1)
    • Observability
      • Prometheus
        • Prometheus for small site (LV.1)
        • Prometheus Operator (LV.2)
    • Security
      • Certbot (LV.1)
      • Falco
      • Hashicorp Vault
    • Collaboration
      • Nextcloud
Powered by GitBook
On this page
  • Nextcloud คืออะไร?
  • (Optional) เชื่อมต่อ Nextcloud กับ OnlyOffice
  • ตัวอย่างการติดตั้งเพื่อใช้งานในองค์กรขนาดเล็ก
  • การเชื่อม SAML กับ nextcloud

Was this helpful?

  1. TOOLS
  2. Collaboration

Nextcloud

Nextcloud คืออะไร?

Nextcloud คือซอฟต์แวร์โอเพนซอร์สที่ให้คุณสร้างระบบ Cloud Storage ส่วนตัวได้เหมือน Google Drive แต่รันอยู่บนเซิร์ฟเวอร์ของคุณเอง ไม่ว่าจะเป็น VPS, server ที่บ้าน หรือแม้แต่ Raspberry Pi ก็สามารถติดตั้งใช้งานได้

Nextcloud รองรับทั้งการ จัดเก็บไฟล์, แชร์ไฟล์, แก้ไขเอกสารออนไลน์, ซิงค์กับอุปกรณ์มือถือ/เดสก์ท็อป, ปฏิทิน, วิดีโอคอล, และสามารถขยายความสามารถด้วยแอปเสริมหลายร้อยตัว

(Optional) เชื่อมต่อ Nextcloud กับ OnlyOffice

OnlyOffice คือชุดซอฟต์แวร์สำนักงานแบบโอเพนซอร์ส ที่ให้คุณ เปิด แก้ไข และทำงานร่วมกันกับเอกสาร Word, Excel, PowerPoint ได้ผ่านเว็บบราวเซอร์ โดยที่ฟีลลิ่งและหน้าตาใกล้เคียงกับ Microsoft Office มากที่สุดในบรรดาเครื่องมือ open source ทั้งหมด

ตัวอย่างการติดตั้งเพื่อใช้งานในองค์กรขนาดเล็ก

map domain nextcloud.office.com มาที่ server

เตรียมไฟล์ TLS Certificate สำหรับ Nextcloud ใส่ไว้ใน folder certs ดังนี้

cert.pem - ไฟล์ cert ของ Nextcloud key.pem - private key ที่เข้าคู่กับไฟล์ cert

เตรียมไฟล์ Caddyfile เพื่อเป็น https proxy ให้กับ Nextcloud

Caddyfile
:443 {
  tls /certs/cert.pem /certs/key.pem

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

  reverse_proxy app:80

  header {
    # Nextcloud required headers
    X-Content-Type-Options "nosniff"
    X-Frame-Options "SAMEORIGIN"
    Referrer-Policy "no-referrer"
    X-XSS-Protection "1; mode=block"
  }
}

เตรียมไฟล์ docker-compose.yml

docker-compose.yml
services:
  caddy:
    image: caddy:alpine
    container_name: nextcloud_proxy
    ports:
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - ./certs:/certs:ro
    depends_on:
      - app
    restart: always

  db:
    image: mysql:8.4.4
    container_name: nextcloud_db
    restart: always
    volumes:
      - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: nextcloud
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: nextcloud

  app:
    image: nextcloud:30.0.8
    container_name: nextcloud_app
    restart: always
    volumes:
      - nextcloud_data:/var/www/html
    environment:
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: nextcloud
      MYSQL_HOST: db
      OVERWRITEHOST: nextcloud.example.com
      OVERWRITEPROTOCOL: https
      OVERWRITECLIURL: https://nextcloud.example.com
    depends_on:
      - db

volumes:
  db_data:
  nextcloud_data:

เริ่ม Deploy ด้วยคำสั่ง

docker compose up -d

ทดสอบใช้งานผ่าน https://nextcloud.example.com

map domain nextcloud.office.com และ office.example.com มาที่ server

เตรียมไฟล์ TLS Certificate สำหรับ Nextcloud ใส่ไว้ใน folder certs ดังนี้

cert.pem - ไฟล์ cert ของ Nextcloud key.pem - private key ที่เข้าคู่กับไฟล์ cert

เตรียมไฟล์ Caddyfile เพื่อเป็น https proxy ให้กับ Nextcloud

Caddyfile
nextcloud.example.com:443 {
  tls /certs/cert.pem /certs/key.pem

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

  reverse_proxy app:80

  header {
    # Nextcloud required headers
    X-Content-Type-Options "nosniff"
    Content-Security-Policy "frame-ancestors 'self' https://nextcloud.example.com https://office.example.com;"
    Referrer-Policy "no-referrer"
    X-XSS-Protection "1; mode=block"
  }
}

office.example.com:443 {
  tls /certs/cert.pem /certs/key.pem

  reverse_proxy office:80

  header {
    # Optional security headers
    X-Content-Type-Options "nosniff"
    Content-Security-Policy "frame-ancestors 'self' https://nextcloud.example.com https://office.example.com;"
    Referrer-Policy "no-referrer"
    X-XSS-Protection "1; mode=block"
  }
}

เตรียมไฟล์ docker-compose.yml

docker-compose.yml
services:
  caddy:
    image: caddy:alpine
    container_name: nextcloud_proxy
    ports:
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile:ro
      - ./certs:/certs:ro
    depends_on:
      - app
    restart: always

  db:
    image: mysql:8.4.4
    container_name: nextcloud_db
    restart: always
    volumes:
      - db_data:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: nextcloud
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: nextcloud

  app:
    image: nextcloud:30.0.8
    container_name: nextcloud_app
    restart: always
    volumes:
      - nextcloud_data:/var/www/html
    environment:
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: nextcloud
      MYSQL_HOST: db
      OVERWRITEHOST: nextcloud.example.com
      OVERWRITEPROTOCOL: https
      OVERWRITECLIURL: https://nextcloud.example.com
    depends_on:
      - db
  office:
    image: onlyoffice/documentserver:8.3.2
    container_name: office
    restart: always
    environment:
      JWT_SECRET: office_jwt
    volumes:
      - office_log:/var/log/onlyoffice
      - office_data:/var/www/onlyoffice/Data
      - office_lib:/var/lib/onlyoffice
      - office_db:/var/lib/postgresql

volumes:
  db_data:
  nextcloud_data:
  office_log:
  office_data:
  office_lib:
  office_db:

เริ่ม Deploy ด้วยคำสั่ง

docker compose up -d

ทดสอบใช้งานผ่าน https://nextcloud.example.com

ไปที่หน้า Administration settings > ONLYOFFICE

ช่อง ONLYOFFICE Docs address ให้ใส่ https://office.example.com ช่อง Secret key (leave blank to disable) ให้ใส่ office_jwt

ทดสอบใช้งานไฟล์ .xlsx หรือ .docx


การเชื่อม SAML กับ nextcloud

เราสามารถทำ SSO กับ nextcloud ได้ โดยการ register nextcloud เป็น app หนึ่งบน Active Directory

Config ฝั่ง Azure AD

  1. ไปที่เมนู Enterprise Application บน Microsoft Azure

  2. คลิก New Application

  3. คลิก Create your own application

  4. กรอกชื่อ app เช่น nextcloud และเลือก Integrate any other application you don't find in the gallery (Non-gallery) แล้วคลิก Create

  5. หลังจาก Create จะได้หน้าการจัดการ Application นี้มา

  6. คลิกเลือก Assign users and groups และกำหนด user หรือ group ที่สามารถเข้าใช้งาน Application นี้ได้ * Group-based assignment จำเป็นต้องมี Microsoft Entra ID P1 or P2 edition ไม่เช่นนั้นต้อง assign user ใน nextcloud เข้า group เองทีละคน

  7. คลิก Setup single sign on

    1. Basic SAML Configuration กรอกค่าดังนี้

      1. Identifier (Entity ID): https://nextcloud.example.com/apps/user_saml/saml/metadata

      2. Reply URL (Assertion Consumer Service URL): https://nextcloud.example.com/apps/user_saml/saml/acs Index: 1

      3. Sign on URL (Optional): https://nextcloud.example.com/login

      4. Logout Url (Optional): https://nextcloud.example.com/logout

    2. Attributes & Claims แก้ไข Claim name ดังนี้

      1. Name: displayname Namespace: ค่าว่าง (เอา namespace http://schemas.xmlsoap.org/ws/2005/05/identity/claims ออก) Source: Attribute Source attribute: user.displayname

      2. ทำซ้ำกับ Claim อื่นๆ email: user.mail firstname: user.givenname lastname: user.surname name: user.principalname

      3. กด Add a group claim เลือก Groups assigned to the application Source attribute: Cloud-only group display names Advanced options: -> Customize the name of the group claim ---> Name: groups

      4. ตรวจผลลัพธ์แล้วกลับไปหน้าก่อน

    3. SAML Certificates คลิก Download Certificate (Base64)

    4. จดค่า ดังนี้เพื่อไปกรอกใน nextcloud Login URL Microsoft Entra Indentifier

Config ฝั่ง Nextcloud

  1. ไปที่ Apps เลือก Featured apps หา app ชื่อ SSO & SAML authentication กดปุ่ม Download and enable

  2. ไปที่ Administration settings เลือก SSO & SAML authentication

  3. Global settings ติ๊กเลือก Allow the use of multiple user back-ends (e.g. LDAP)

  4. General ช่อง Attribute to map the UID to. กรอก name ช่อง Optional display name of the identity provider (default: "SSO & SAML log in") กรอกชื่อปุ่ม Login เช่น Azure AD

  5. Service Provider Data (ข้าม)

  6. Identity Provider Data ช่อง Identifier of the IdP entity (must be a URI) กรอกค่าที่จดจาก Microsoft Entra Identifier (7d) ช่อง URL Target of the IdP where the SP will send the Authentication Request Message กรอกค่าจาก Login URL (7d)

  7. เปิดส่วนที่ซ่อนอยู่ใต้ Show optional Identity Provider settings… ช่อง Public X.509 certificate of the IdP กรอกค่า BASE64 ที่ได้จาก SAML Certificate (7c)

  8. Attribute mapping เปิดส่วนที่ซ่อนใต้ Show attribute mapping settings… ช่อง Attribute to map the displayname to. กรอก displayname ช่อง Attribute to map the email address to. กรอก email ช่อง Attribute to map the users groups to. กรอก groups (ถ้า Azure AD)

  9. Nextcloud จะ Auto Save config ที่เรา set ไป ลองทดสอบไปหน้าอื่น แล้วกลับมา ว่าค่ายังอยู่ครบหรือไม่ หลังจากนั้นทดสอบ login Nextcloud ด้วย Azure AD


PreviousCollaboration

Last updated 16 days ago

Was this helpful?