외부 Nginx 리버스 프록시 뒤에 넥스트클라우드를 배치할 때 발생하는 신뢰할 수 없는 도메인(Access through untrusted domain) 오류와 프로토콜/호스트 불일치 문제를 해결하려면, 내부 넥스트클라우드의 config.php 파일에 신뢰 도메인(trusted_domains) 및 프록시/오버라이드 파라미터를 올바르게 설정해야 합니다. [1, 2, 3]

Snap 버전으로 설치된 넥스트클라우드 기준의 설정 경로와 수정 방법은 다음과 같습니다.

설정 파일 위치 및 편집 방법

  • 설치 경로(Snap): /var/snap/nextcloud/current/nextcloud/config/config.php
  • 편집 전 백업: sudo cp /var/snap/nextcloud/current/nextcloud/config/config.php /var/snap/nextcloud/current/nextcloud/config/config.php.bak
  • 파일 편집 명령어: sudo nano /var/snap/nextcloud/current/nextcloud/config/config.php
  • (참고: Snap이 아닌 일반 LAMP 스택 설치 시 경로 보통 /var/www/nextcloud/config/config.php) [1, 2, 3]

완성된 config.php 설정 예시 파일

config.php 내부의 array 리턴 블록 안쪽에 아래와 같이 항목을 추가하거나 수정합니다. [1]

php

<?php
$CONFIG = array (
  'instanceid' => 'ocxxxxxxxxxx',
  'passwordsalt' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'trusted_domains' => array (
    0 => '192.168.X.X',                  # 내부 넥스트클라우드 서버 IP 또는 로컬 IP
    1 => 'cloud.example.com',             # 외부에서 접속하는 실제 도메인
  ),
  'overwrite.cli.url' => 'https://cloud.example.com', # CLI 및 알림 링크의 기준 주소
  'overwritehost' => 'cloud.example.com',             # 리버스 프록시 호스트 명시
  'overwriteprotocol' => 'https',                     # 프록시가 받는 프로토콜이 HTTPS임을 강제
  'trusted_proxies' => array (
    0 => '192.168.X.Y',                   # 외부 Nginx 리버스 프록시 서버의 IP
  ),
  'forwarded_for_headers' => array('HTTP_X_FORWARDED_FOR'), # 원래 클라이언트 IP 보존 설정
  'dbtype' => 'mysql',
  # ... 나머지 데이터베이스 및 기타 설정 유지 ...
);

코드를 사용할 때는 주의가 필요합니다.

CLI 명령어(occ)를 이용한 간편 설정 방법

직접 파일을 편집하는 대신 occ 도구 명령어를 사용해 신뢰 도메인, 프록시, 호스트 설정을 한 줄씩 등록할 수 있습니다. (Snap 버전 기준) [1]

  • 신뢰 도메인 추가: sudo nextcloud.occ config:system:set trusted_domains 1 --value="cloud.example.com"
  • 프록시 프로토콜/호스트: sudo nextcloud.occ config:system:set overwriteprotocol --value="https"...overwritehost --value="cloud.example.com"
  • 신뢰 프록시 IP: sudo nextcloud.occ config:system:set trusted_proxies 0 --value="192.168.X.Y" [1, 2]

설정 반영 후 캘린더/주소록(.well-known) 리다이렉트 설정이나 대용량 파일 업로드 시 504 타임아웃 예외 처리에 대한 추가 튜토리얼이 필요하신가요?

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다