안녕하세요 모두
문서와 게시된 설정 및 권장 사항을 모두 확인하고, 제 상황에 맞게 수정해 보려 시도했습니다.
매우 단순해 보이는 작업인데, 제안된 어떤 솔루션도 작동하지 않아 incredibly frustrate합니다.
저희 환경:
- AWS EC2 인스턴스를 사용 중이며, 구체적으로는 AWS Linux 2 AMI입니다;
- apache2가 실행 및 설정되어 있습니다;
- 해당 인스턴스는 AWS 로드 밸런서에 의해 참조되는 AWS 타깃 그룹의 일부입니다;
- SSL/TLS 인증서는 AWS에서 제공하며 로드 밸런서에 연결되어 있습니다;
- 도메인 제공자는
name.com입니다; - 설정의 일환으로 CNAME 레코드를 사용하여 여러 서브도메인을 AWS 로드 밸런서로 라우팅하며, 로드 밸런서가 EC2 인스턴스로의 트래픽을 관리합니다;
- 로드 밸런서로 라우팅되고 웹 사용자에게 제공되는 모든 트래픽은 보안(HTTPS)입니다;
- 서버에서 세 개의 독립적인 node express 애플리케이션을 실행하고 있습니다;
- 포트는 express 서버 설정의 일부로 express에서 정의되며, 현재 3000, 4000, 5000 포트입니다;
- 트래픽은 서브도메인을 기준으로 apache가 관련 웹 앱으로 라우팅합니다. 예를 들어:
<VirtualHost *:80>
ServerName subdomain.domain.io
ProxyPreserveHost On
ProxyPass "/" "http://localhost:4000/"
ProxyPassReverse "/" "http://localhost:4000/"
</VirtualHost>
-
특별히 관련은 없지만, 서버 재시작 시 자동으로 시작되도록 PM2를 사용하여 express 앱을 관리합니다.
-
동일한 서버에 docker가 설치되어 있습니다;
-
app.yaml 복사본을 사용하여 discourse도 설치했습니다(Run other websites on the same machine as Discourse - #182 by angus 를 참고함).
현재 상태:
- Docker는 실행 중입니다
- Discourse 앱(컨테이너)은 실행 중입니다
- Express 앱들은 모두 실행 중이며 apache에 의해 올바르게 라우팅되고 있습니다
메모:
- 처음에는 문서대로 포트를 노출하지 않고 앱을 빌드해 보았으나, 작동하지 않아 HTTP 포트 80으로 포트 8000을 노출했습니다;
- 제 단순한 이해에 따르면 docker는 집과 같고, 다양한 컨테이너는 방과 같습니다. Docker는 앱이 어떻게 접근되는지(즉, 어떤 방을 접근할지)를 결정합니다. 포트 8000을 노출하면 이제 8000이 노출되었으므로 다른 express 앱처럼 포트 8000을 참조할 수 있을 것이라 생각했습니다. 하지만 이는 작동하지 않으며, apache에서 시도한 것의 예시는 다음과 같습니다:
# FAQ (DISCOURSE ROUTES)
<VirtualHost *:80>
ServerName discourse.domain.io
ProxyPreserveHost On
ProxyPass "/" "http://localhost:8000/"
ProxyPassReverse "/" "http://localhost:8000/"
</VirtualHost>
- 단순한 테스트는 서버에서 브라우저에 localhost:8000을 입력해 보는 것이었습니다. 서버는 chromium이 설치된 AWS 가이드입니다. 이것이 즉시 해결되지 않는다는 사실은 문제가 있으며 제 이해에 근본적인 무언가가 빠져 있음을 알려줍니다. 제 웹 앱은 express 설정에서 지정하는 포트에서 실행되고 사용 가능하며, docker 컨테이너도 동일할 것으로 기대했습니다.
추가 메모:
- NGINX를 apache와 docker 앞에 배치하여
discourse.domain.io트래픽을 로컬 서버의 포트 8000(즉, docker 컨테이너를 위해 노출된 포트)으로 라우팅하고, *.domain.io의 모든 다른 트래픽을 예를 들어 포트 9000의 apache로 라우팅한 후, 포트 9000에서 트래픽을 라우팅하도록 가상 호스트 구성을 변경하는 것이 잠재적인 해결책임을 인지하고 있습니다. 즉, 다음과 같이:
# EXPRESS APP ROUTING IN APACHE
<VirtualHost *:9000>
ServerName other_sub_domains.domain.io
ProxyPreserveHost On
ProxyPass "/" "http://localhost:4000/"
ProxyPassReverse "/" "http://localhost:4000/"
</VirtualHost>
- 제게 이것은 완전히 불필요해 보입니다. 도메인
discourse.domain.io가 apache로 라우팅되고 apache가 요청을 받은 후 라우팅을 시도한다면, docker 컨테이너의 노출된 포트로 가리키는 것만큼 간단해야 합니다. - 또한 서버 자체에서 localhost:8000이 해결되지 않는다면, 이 방식은 어차피 작동하지 않을 것입니다.
현재 discourse docker 컨테이너로 이동하려고 할 때 chrome에서 502 오류가 발생합니다. (위 스크린샷 참조).
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
##
## BE *VERY* CAREFUL WHEN EDITING!
## YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT!
## visit http://www.yamllint.com/ to validate this file as needed
templates:
- "templates/postgres.template.yml"
- "templates/redis.template.yml"
- "templates/web.template.yml"
- "templates/web.ratelimited.template.yml"
- "templates/web.socketed.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:
- "8000: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"
## can improve sorting performance, but adds memory usage per-connection
#db_work_mem: "40MB"
## Which Git revision should this container use? (default: tests-passed)
#version: tests-passed
env:
LC_ALL: en_US.UTF-8
LANG: en_US.UTF-8
LANGUAGE: 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
## Required. Discourse will not work with a bare IP number.
DISCOURSE_HOSTNAME: 'discourse.domain.io'
## 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@domain.io'
## TODO: The SMTP mail server used to validate new accounts and send notifications
# SMTP ADDRESS, username, and password are required
# WARNING the char '#' in SMTP password can cause problems!
DISCOURSE_SMTP_ADDRESS: email-smtp.us-east-1.amazonaws.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: ******
DISCOURSE_SMTP_PASSWORD: ******
#DISCOURSE_SMTP_ENABLE_START_TLS: true # (optional, default true)
#DISCOURSE_SMTP_DOMAIN: ****** # (required by some providers)
#DISCOURSE_NOTIFICATION_EMAIL: ****** # (address to send notifications from)
## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
#LETSENCRYPT_ACCOUNT_EMAIL: me@example.com
## The http or https CDN address for this Discourse instance (configured to pull)
## see https://meta.discourse.org/t/14857 for details
#DISCOURSE_CDN_URL: https://discourse-cdn.example.com
## The maxmind geolocation IP address key for IP address lookup
## see https://meta.discourse.org/t/-/137387/23 for details
#DISCOURSE_MAXMIND_LICENSE_KEY: 1234567890123456
## 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:
## After getting the first signup email, re-comment the line. It only needs to run once.
#- exec: rails r "SiteSetting.notification_email='info@unconfigured.discourse.org'"
- exec: echo "End of custom commands"
제 도메인, 이메일 주소 및 이메일 구성은 정확합니다. 언급했듯이, SSL/TLS 구성은 필요하지 않습니다.
요청 사항:
- 이 설정을 작동시키는 유일한 방법이 NGINX 솔루션인 것이며, 그렇다면 설정 단계에 대해 더 명확한 설명이 가능한가요? discourse를 작동시키기 위해 서버를 처음부터 다시 시작할 위치에 있지 않으며, 보장도 없습니다.
- Discourse behind reverse proxy and https - #2 by itsbhanusharma 에서 @Dark Matter 님은 다음을 apache2 솔루션으로 제공했지만, 이 솔루션이 node express 환경을 고려한 것이라 생각하지 않으며, 제 localhost:8000이 해결되지 않으므로 이것이 작동할지 확실하지 않습니다:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName discourse.example.com
DocumentRoot /website/discourse
RewriteEngine On
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / unix:/var/discourse/shared/socket-only/nginx.http.sock|http://localhost/
ProxyPassReverse / unix:/var/discourse/shared/socket-only/nginx.http.sock|http://localhost/
ErrorLog /var/log/apache2/discourse.error.log
LogLevel warn
CustomLog /var/log/apache2/discourse.access.log combined
RewriteCond %{SERVER_NAME} =discourse.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
- 문제는 제 discourse 구성에 있는 것인가요? 아마도 제 apache 라우팅 문제일까요(의심 중)? 아니면 여기서 더 근본적인 무언가를 놓치고 있는 것인가요?
- 이것이 해결되면 향후 많은 사용자에게 도움이 될 것이라고 생각합니다.
- 1등 상은 서버 내에서 discourse로 로컬 라우팅을 하는 것입니다.
- 그 다음 상은 URL을 통한 라우팅입니다.
감사합니다
Matthew Lucas



