Discourse docekr部署教程
开始之前
服务器配置说明:
docker部署教程
安装docker
见本站docker安装教程:https://halo.blog360.sbs/archives/dockeran-zhuang-jiao-cheng
Discourse 镜像下载容器启动
下载项目源码
git clone https://github.com/discourse/discourse_docker.git /opt/discourse
cd /opt/discourse
chmod 700 containers
执行生成配置文件脚本
./discourse-setup
出现提示时回答以下问题:
Hostname for your Discourse? [discourse.example.com]:
Email address for admin account(s)? [me@example.com,you@example.com]:
SMTP server address? [smtp.example.com]:
SMTP port? [587]:
SMTP user name? [user@example.com]:
SMTP password? [pa$$word]:
Let's Encrypt account email? (ENTER to skip) [me@example.com]:
Optional Maxmind License key () [xxxxxxxxxxxxxxxx]:
从电子邮件设置中获取 SMTP 详细信息,请务必完成该部分。 Let’s Encrypt 帐户设置旨在为您的网站提供免费的 HTTPS 证书,如果希望网站安全,请务必进行设置。 这将代表生成一个app.yml配置文件,然后启动引导程序。Bootstrapping 需要2-8 分钟来设置您的 Discourse。如果需要在引导后更改这些设置,可以./discourse-setup再次运行(它将重新使用文件中以前的值)或使用和 then/containers/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"
## 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: "1024MB"
## 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
TZ: Asia/Shanghai
# 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: 4
#HTTP_PROXY: "http://192.168.73.1:3067"
#HTTPS_PROXY: "http://192.168.73.1:3067"
DISCOURSE_ENABLE_HTTPS: false # 完全禁用HTTPS
DISCOURSE_SKIP_HTTPS_REDIRECT: true # 禁止HTTPS重定向
# 强制HTTPS资源生成 (核心修复)
DISCOURSE_FORCE_HTTPS: true # 生成HTTPS资源链接
DISCOURSE_USE_HTTPS: true # 双重确保HTTPS资源
# 代理相关设置
# DISCOURSE_RELATIVE_URL_ROOT: "/" # 修复路径问题
UNICORN_LISTEN_ADDRESS: "0.0.0.0" # 监听所有接口
# 代理头识别设置 (解决无限重定向)
RACK_ENV: production
RAILS_ENV: production
## TODO: The domain name this Discourse instance will respond to
## Required. Discourse will not work with a bare IP number.
DISCOURSE_HOSTNAME: test.blog360.sbs
## 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: 'admin@qq.com'
## TODO: The SMTP mail server used to validate new accounts and send notifications
# SMTP ADDRESS is required
# WARNING: SMTP password should be wrapped in quotes to avoid problems
DISCOURSE_SMTP_ADDRESS: smtp.qq.com
DISCOURSE_SMTP_PORT: 587
DISCOURSE_SMTP_USER_NAME: admin@qq.com
DISCOURSE_SMTP_PASSWORD: "1234567"
#DISCOURSE_SMTP_FORCE_TLS: true ssl(465端口)协议开启此项关闭START_TLS
DISCOURSE_SMTP_ENABLE_START_TLS: true
DISCOURSE_SMTP_DOMAIN: admin@qq.com # (required by some providers)
DISCOURSE_NOTIFICATION_EMAIL: admin@qq.com
LETSENCRYPT_ACCOUNT_EMAIL: admin@qq.com
#DISCOURSE_SMTP_OPENSSL_VERIFY_MODE: peer # (optional, default: peer, valid values: none, peer, client_once, fail_if_no_peer_cert)
#DISCOURSE_SMTP_AUTHENTICATION: plain # (default: plain, valid values: plain, login, cram_md5)
## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
## 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 account ID and license key for IP address lookups
## see https://meta.discourse.org/t/-/173941 for details
#DISCOURSE_MAXMIND_ACCOUNT_ID: 123456
#DISCOURSE_MAXMIND_LICENSE_KEY: 1234567890123456
docker_params:
memory: 1g
memory-swap: "1g"
## The Docker container is stateless; all data is stored in /shared
volumes:
- volume:
host: /opt/discourse/shared/standalone
guest: /shared
- volume:
host: /opt/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"
配置总结:
配置代理
配置系统级别代理或者配置github代理
配置系统代理
# 配置app.yml文件。容器系统代理
env:
HTTP_PROXY: "http://192.168.73.1:3067"
HTTPS_PROXY: "http://192.168.73.1:3067"
国内代理源可以去2025年07月更新!18个Github镜像站,国内更快部署下载或者Github Proxy 文件代理加速修改可用镜像源
运行启动命令根据提示连接异常域名,执行查找脚本更改代理
grep -ril --exclude-dir={.git,.svn} '查找的字符串' /文件路径 2>/dev/null
启动 Discourse
配置完成后自动构建并启动容器(首次启动约需 10-15 分钟):
# 重构app
./launcher rebuild app
# 查看容器状态
sudo ./launcher status app
# 日志监控
sudo ./launcher logs app
Discourse 发布教程
nginx 发布教程
添加配置域名发布文件
server {
listen 80;
server_name test.blog360.sbs;
client_max_body_size 20m;
# 主请求代理
location / {
proxy_pass http://172.30.0.2:80;
# 关键头信息传递 (解决混合内容问题)
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; # 告知Discourse使用HTTPS
# WebSocket支持
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# 缓存优化
proxy_cache_bypass $http_upgrade;
# 修复静态资源路径
sub_filter_once off;
sub_filter_types text/html text/css application/javascript;
}
}
申请免费证书(ssl证书可选)
安装Certbot工具
# Ubuntu/Debian
sudo apt update
sudo apt install certbot python3-certbot-nginx
# CentOS/RHEL
sudo yum install epel-release
sudo yum install certbot python3-certbot-nginx
申请ssl证书(nginx)
sudo certbot --nginx -d your-domain.com
替换
your-domain.com
为你的域名
修改app.yml配置文件
DISCOURSE_ENABLE_HTTPS: false # 完全禁用HTTPS
DISCOURSE_SKIP_HTTPS_REDIRECT: true # 禁止HTTPS重定向
# 强制HTTPS资源生成 (核心修复)
DISCOURSE_FORCE_HTTPS: true # 生成HTTPS资源链接
DISCOURSE_USE_HTTPS: true # 双重确保HTTPS资源
# 代理相关设置
# DISCOURSE_RELATIVE_URL_ROOT: "/" # 修复路径问题
UNICORN_LISTEN_ADDRESS: "0.0.0.0" # 监听所有接口
# 代理头识别设置 (解决无限重定向)
RACK_ENV: production
RAILS_ENV: production
重新构建
# 重构app
./launcher rebuild app