我终于让它运行起来了,并想把所有步骤整合在一起,以防有人需要。
此信息汇总自本论坛的不同主题。感谢 @brahn 和 @techAPJ。
本指南假设您已完成 Let’s Encrypt 的初始设置:
完成初始设置后,需要在 app.yml 的 hooks 部分添加以下内容。它将实现两个功能:
- 为
example.com和www.example.com都配置 SSL。只需将example.com替换为您的域名。 - 将
example.com重定向到www.example.com。
如果您知道如何改进,请告诉我。
hooks:
after_code:
- exec:
cd: $home/plugins
cmd:
- git clone https://github.com/discourse/docker_manager.git
after_web_config:
- replace:
filename: /etc/nginx/nginx.conf
from: /sendfile.+on;/
to: |
server_names_hash_bucket_size 64;
sendfile on;
- file:
path: /etc/nginx/conf.d/discourse_redirect_1.conf
contents: |
server {
listen 443;
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
}
after_ssl:
- replace:
filename: "/etc/runit/1.d/letsencrypt"
from: /-k 4096 -w \\/var\\/www\\/discourse\\/public/
to: |
-d www.example.com -d example.com -k 4096 -w /var/www/discourse/public
- replace:
filename: "/etc/runit/1.d/letsencrypt"
from: /-k 4096 --force -w \\/var\\/www\\/discourse\\/public/
to: |
-d www.example.com -d example.com -k 4096 --force -w /var/www/discourse/public
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: /return 301 https.+/
to: |
return 301 https://$host$request_uri;
- replace:
filename: "/etc/nginx/conf.d/discourse.conf"
from: /gzip on;[^\}]+\}/m
to: |
gzip on;
add_header Strict-Transport-Security 'max-age=31536000'; # 记住证书一年,并自动通过 HTTPS 连接
如往常一样,请记住 app.yml 文件中的空格和缩进非常重要。编辑完成后,您需要使用以下命令重建容器:
cd /var/discourse
./launcher rebuild app