@Teraterayuki 님, 안녕하세요.
Discourse 컨테이너의 유닉스 도메인 소켓으로 리버스 프록싱하기 위한 작동하는 Apache2 가상 호스트 설정 예시를 아래에 드립니다:
포트 80
<VirtualHost *:80>
ServerName mysite.mydomain.com
ServerAdmin webmaster@localhost
ProxyPreserveHost On
#ProxyPass / http://127.0.0.1:8888/
#ProxyPassReverse / http://127.0.0.1:8888/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/community_errors.log
CustomLog ${APACHE_LOG_DIR}/community.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ModPagespeed Off
RewriteEngine on
RewriteCond %{SERVER_NAME} =mysite.mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
포트 443
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mysite.mydomain.com
ServerAdmin webmaster@localhost
#SSLProxyEngine on #enable this after Let's encrypt is setup on the reverse proxy
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (Bytespider|Yandex|Wget|seocompany|CCBot|Cincraw) [NC]
RewriteRule . - [R=403,L]
ProxyPreserveHost On
ProxyRequests Off
RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME}
RequestHeader set X-Real-IP expr=%{REMOTE_ADDR}
#ProxyPass / http://127.0.0.1:8888/
#ProxyPassReverse / http://127.0.0.1:8888/
ProxyPass / unix:/var/discourse/shared/socket-only/nginx.http.sock|http://localhost/
ProxyPassReverse / unix:/var/discourse/shared/socket-only/nginx.http.sock|http://localhost/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/community_errors_ssl.log
#CustomLog ${APACHE_LOG_DIR}/community_ssl.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ModPagespeed Off
SSLCertificateFile /etc/letsencrypt/live/mysite.mydomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mysite.mydomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
이 설정에서 프록시는 웹 소켓(ws)이 아니라 유닉스 소켓으로 연결된다는 점을 유의해 주세요.
또한 이 설정에서는 Let’s Encrypt 정보를 수동으로 추가할 필요가 없습니다. 다음으로 시작할 수 있습니다:
Certbot 실행 전 포트 80
<VirtualHost *:80>
ServerName mysite.mydomain.com
ServerAdmin webmaster@localhost
ProxyPreserveHost On
#ProxyPass / http://127.0.0.1:8888/
#ProxyPassReverse / http://127.0.0.1:8888/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/community_errors.log
CustomLog ${APACHE_LOG_DIR}/community.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ModPagespeed Off
</VirtualHost>
Certbot 실행 전 포트 443
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName mysite.mydomain.com
ServerAdmin webmaster@localhost
#SSLProxyEngine on #enable this after Let's encrypt is setup on the reverse proxy
RewriteEngine On
ProxyPreserveHost On
ProxyRequests Off
RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME}
RequestHeader set X-Real-IP expr=%{REMOTE_ADDR}
#ProxyPass / http://127.0.0.1:8888/
#ProxyPassReverse / http://127.0.0.1:8888/
ProxyPass / unix:/var/discourse/shared/socket-only/nginx.http.sock|http://localhost/
ProxyPassReverse / unix:/var/discourse/shared/socket-only/nginx.http.sock|http://localhost/
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/community_errors_ssl.log
#CustomLog ${APACHE_LOG_DIR}/community_ssl.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
ModPagespeed Off
</VirtualHost>
</IfModule>
그 다음, 다음 명령을 실행하면:
certbot -d mysite.mydomain.com
친절한 certbot이 필요한 SSL 코드를 자동으로 추가해 줍니다.
certbot이 설정 코드를 추가하고 모든 것이 예상대로 작동하는 것을 확인한 후, 다음 줄의 주석을 해제할 수 있습니다:
#SSLProxyEngine on #enable this after Let's encrypt is setup on the reverse proxy
그리고 apache2를 다시 시작하세요.
@Teraterayuki 님께 도움이 되기를 바랍니다.
건강하세요.
마무리 노트:
- Apache2 리버스 프록시 설정에서
haproxy를 사용하지 않는다는 점을 유의해 주세요.haproxy는 (우리에게) 실질적인 이점이 거의 없으면서 불필요한 복잡성을 더합니다. 따라서 우리는 리버스 프록시로 apache2를 "간편한 방법"으로 실행합니다.haproxy를 사용하려는 경우 결과는 다를 수 있습니다(YMMV). 하지만 솔직히 말하면, 우리는 (프로덕션 환경의 여러 Apache2 리버스 프록시 설정에서)haproxy를 사용하지 않으며, 리버스 프록시로 apache2를 사용하는 데 결코 문제가 없었습니다.
mod_pagespeed를 사용하지 않는 경우 해당 줄들을 주석 처리하세요. 하지만mod_pagespeed를 실행 중이라면, Discourse로 리버스 프록싱할 때 가상 호스트별로mod_pagespeed를 꺼야 합니다.
최선을 다해 돕고자 합니다. 조금이라도 도움이 되기를 바랍니다.