이는 자체 호스팅 Discourse 설치에서 환경 변수를 설정하는 방법(how-to)에 대한 가이드입니다.
필요한 사용자 권한: 관리자
환경 변수는 Discourse 인스턴스를 구성하는 데 중요한 역할을 합니다. API 키와 데이터베이스 비밀번호와 같은 민감한 데이터를 저장할 수 있어 설치를 더 안전하고 유연하게 만들어 줍니다. Discourse에서 환경 변수는 Docker 컨테이너 설정 내의 app.yml 파일에 설정됩니다.
.yml(YAML) 파일에 환경 변수를 추가하는 것은 간단합니다. 다음은 기본적인 예시입니다:
# This is a YAML file with environmental variables
env:
VARIABLE_NAME: "Variable Value"
ANOTHER_VARIABLE: "Another Value"
Discourse Docker 컨테이너의 맥락에서 환경 변수는 app.yml 파일의 env 섹션에 저장됩니다.
다음은 app.yml 파일의 예시입니다:
## this is the all-in-one, standalone Discourse Docker container template
##
## After making changes to this file, you must rebuild
## /var/discourse/launcher rebuild app
##
templates:
- "templates/postgres.template.yml"
- "templates/redis.template.yml"
- "templates/web.template.yml"
- "templates/web.ratelimited.template.yml"
## Uncomment these two lines if you wish to add Lets Encrypt (https)
#- "templates/web.ssl.template.yml"
#- "templates/web.letsencrypt.ssl.template.yml"
## which TCP/IP ports should this container expose?
## If you want Discourse to share a port with another webserver like Apache or nginx,
## see https://meta.discourse.org/t/17247 for details
expose:
- "80:80" # http
- "443:443" # https
params:
db_default_text_search_config: "pg_catalog.english"
## Set db_shared_buffers to a max of 25% of the total memory.
## will be set automatically by bootstrap based on detected RAM, or you can override
db_shared_buffers: "256MB"
env:
LANG: en_US.UTF-8
# DISCOURSE_DEFAULT_LOCALE: en
## How many concurrent web requests are supported? Depends on memory and CPU cores.
## will be set automatically by bootstrap based on detected CPUs, or you can override
UNICORN_WORKERS: 3
## TODO: The domain name this Discourse instance will respond to
DISCOURSE_HOSTNAME: 'discourse.example.com'
## Uncomment if you want the container to be started with the same
## hostname (-h option) as specified above (default "$hostname-$config")
#DOCKER_USE_HOSTNAME: true
## TODO: List of comma delimited emails that will be made admin and developer
## on initial signup example 'user1@example.com,user2@example.com'
DISCOURSE_DEVELOPER_EMAILS: 'user@example.com'
## TODO: The SMTP mail server used to validate new accounts and send notifications
DISCOURSE_SMTP_ADDRESS: smtp.example.com # (mandatory)
DISCOURSE_SMTP_PORT: 587 # (optional)
DISCOURSE_SMTP_USER_NAME: user@example.com # (optional)
DISCOURSE_SMTP_PASSWORD: a_s3cr3t_p@ssword # (optional)
#DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)
## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
#LETSENCRYPT_ACCOUNT_EMAIL: me@example.com
## The CDN address for this Discourse instance (configured to pull)
#DISCOURSE_CDN_URL: //discourse-cdn.example.com
## The Docker container is stateless; all data is stored in /shared
volumes:
- volume:
host: /var/discourse/shared/standalone
guest: /shared
- volume:
host: /var/discourse/shared/standalone/log/var-log
guest: /var/log
## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
after_code:
- exec:
cd: $home/plugins
cmd:
- git clone https://github.com/discourse/docker_manager.git
## Any custom commands to run after building
run:
- exec: echo "Beginning of custom commands"
## If you want to set the 'From' email address for your first registration, uncomment and change:
#- exec: rails r "SiteSetting.notification_email='info@unconfigured.discourse.org'"
## After getting the first signup email, re-comment the line. It only needs to run once.
- exec: echo "End of custom commands"
자, 이제 사이트에 환경 변수를 추가하는 작업을 시작해 봅시다! ![]()
다음 설명은 표준 Discourse 설치를 기준으로 작성되었습니다.
서버에 로그인하기
PuTTY와 같은 도구나 Unix 기반 시스템의 터미널을 사용하여 서버에 SSH로 접속하세요.
ssh username@your-server-ip
Discourse 디렉터리로 이동하기
서버에 접근한 후, Discourse Docker 설정이 포함된 디렉터리로 이동하세요. 이는 일반적으로 /var/discourse 위치에 있습니다.
cd /var/discourse
app.yml 파일 열기
텍스트 편집기로 app.yml 파일을 열어야 합니다. 이 예시에서는 nano를 사용합니다.
nano containers/app.yml
환경 변수 추가하기
app.yml 파일에서 env 섹션을 찾을 수 있습니다. 여기에 환경 변수를 추가할 수 있습니다.
env:
DISCOURSE_HOSTNAME: 'discourse.example.com'
DISCOURSE_SMTP_ADDRESS: smtp.example.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: user@example.com
DISCOURSE_SMTP_PASSWORD: a_s3cr3t_p@ssword
```\n
예를 들어, [크로스 오리진 리소스 공유(CORS)](https://meta.discourse.org/t/setup-cross-origin-resource-sharing-cors/270819)를 활성화하기 위해 `DISCOURSE_ENABLE_CORS` 환경 변수를 `true`로 설정하려면, `env` 섹션에 다음 줄을 추가합니다:
env:
DISCOURSE_ENABLE_CORS: “true”
…
> :person_tipping_hand: 여기서는 공백과 포맷이 중요하므로, 새로운 줄에 대해 올바른 들여쓰기(공백 2개)를 유지하는지 확인하세요.
변수를 수정한 후 파일을 저장하고 닫으세요.
## Discourse 컨테이너 다시 빌드하기
마지막으로, 변경 사항이 적용되도록 Discourse Docker 컨테이너를 다시 빌드해야 합니다. 다음 명령을 사용하여 수행할 수 있습니다:
./launcher rebuild app
대안으로, 재빌드 없이 실행 중인 컨테이너의 환경 변수를 업데이트하려면 다음을 사용할 수도 있습니다:
./launcher destroy app
./launcher start app
재빌드 과정이 완료되면, 업데이트된 환경 변수가 Discourse 애플리케이션에서 사용할 수 있게 됩니다! :tada: