基于debian12(宝塔环境),nginx作为代理进行搭建,如有不同之处请自行解决
本次安装路径为:/www/dk_project/dk_app/discourse/

#创建discourse目录
mkdir /www/dk_project/dk_app/discourse/
#进入discourse目录
cd /www/dk_project/dk_app/discourse/
#克隆项目
git clone https://github.com/discourse/discourse_docker.git .
#把该discourse目录加入全局信任列表,防止警告报错信息
git config --global --add safe.directory /www/dk_project/dk_app/discourse
#复制下方的app.yml文件,然后保存到/www/dk_project/dk_app/discourse/containers 路径下,并改名为app.yml
chmod o-rwx containers/app.yml
#编译容器
./launcher rebuild app

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:
  - "10080:80"   # http 
##  - "10443: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)
  # https://meta.discourse.org/c/announcements/13 查看最新正式版本号,如v3.4.7,或使用stable,无需手动查看最新版本test-passed、beta、stable
  #version: v3.4.7
  version: stable

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: 'baidu.com'
  DISCOURSE_HOSTNAME: '你的域名'

  ## 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@baidu.com'
  DISCOURSE_DEVELOPER_EMAILS: '这里填管理员邮箱'

  ## 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.baidu.com
  DISCOURSE_SMTP_ADDRESS: 这里填SMTP发件地址
  DISCOURSE_SMTP_PORT: 587
  #DISCOURSE_SMTP_USER_NAME: noreply@baidu.com
  DISCOURSE_SMTP_USER_NAME: 发件邮箱
  #smtp的发件密码尽量不要带特殊符号#
  #DISCOURSE_SMTP_PASSWORD: "abc123456"
  DISCOURSE_SMTP_PASSWORD: "密码"
  #DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default: true)
  #DISCOURSE_SMTP_DOMAIN: discourse.example.com    # (required by some providers)
  #DISCOURSE_NOTIFICATION_EMAIL: noreply@discourse.example.com    # (address to send notifications from)
  #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
  #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 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

## The Docker container is stateless; all data is stored in /shared
volumes:
  - volume:
      host: /www/dk_project/dk_app/discourse/data/shared
      guest: /shared
  - volume:
      host: /www/dk_project/dk_app/discourse/data/log
      guest: /var/log
  - volume:
      host: /www/dk_project/dk_app/discourse/data/lib/redis
      guest: /var/lib/redis
  - volume:
      host: /www/dk_project/dk_app/discourse/data/lib/postgresql/data
      guest: /var/lib/postgresql/data
#  - volume:
#      host: /www/dk_project/dk_app/discourse/data/plugins
#      guest: /var/www/discourse/plugins
#  - volume:
#      host: /www/dk_project/dk_app/discourse/data/config
#      guest: /var/www/discourse/config
## 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"

安装过后再宝塔docker里添加个反代即可
2025-08-12T03:03:34.png
2025-08-16T12:06:08.png

常见问题:
如果安装主题后,出现错误页面可以尝试在你的网站后面加上/safe-mode ,如https://discourse.com/safe-mode 进入安全模式后进行调试,如禁用相关插件或者主题或配置等
常见命令:

#重新构建镜像
./launcher rebuild app
# 重启应用
./launcher restart app  
# 进入容器
./launcher enter app  
# 清除缓存
rake tmp:clear  
# 重新编译静态资产(包括主题样式)
rake assets:precompile  
# 查看是否有未完成的迁移(状态为「down」)
rake db:migrate:status
# 若有未完成,执行迁移    
rake db:migrate          
# 退出并重启容器
exit
#启动 Rails 控制台
# 进入容器
./launcher enter app 
rails c
# 查看所有主题(正常情况下至少包含默认主题)
Theme.all.each { |t| puts "#{t.name} - ID: #{t.id}" }  

# 查看当前启用的主题(站点设置)
SiteSetting.default_theme_id   # 应为默认主题 ID(如 1)

# 在 Rails 控制台执行:将默认主题设为 Discourse 官方默认(ID=1)
# 强制重置默认主题(极端手段,谨慎操作)若怀疑主题数据异常,可尝试重置为官方默认主题
SiteSetting.default_theme_id = 1  
SiteSetting.mobile_theme_id = 1 

安全方面(引用L站站长方案):
1.服务器如果需要出口访问,请设置好全局http或者socket代理,避免被攻击者获取到源IP
2.如果使用clouflare的cdn服务,ssl证书请直接在cloudflare中申请CA证书,避免自行申请ssl的免费证书,防止ssl溯源到源ip,然后导入到宝塔面板中
3.服务器开启白名单访问,只允许CDN厂商的IP进行访问,如cloudflare、edgeone、aliyun esa等等
4.discourse相关的接口,在cdn厂商中配置访问速率
5.如果你的邮局和discourse部署在同一服务器中,请尽量不要使用smtp发件,会暴露服务器本身ip,一般建议使用第三方邮局

以debian12为例,配置全局出口代理
打开终端并编辑 ~/.bashrc 或 vi /etc/environment 文件,添加或修改以下环境变量

export http_proxy="http://username:password@<proxy_address>:<proxy_port>"
export https_proxy="http://username:password@<proxy_address>:<proxy_port>"
export ftp_proxy="http://username:password@<proxy_address>:<proxy_port>"
# 如果是 SOCKS 代理
export socks_proxy="socks://username:password@<proxy_address>:<proxy_port>" 

对于 ~/.bashrc,运行 source ~/.bashrc 使更改立即生效。
对于 /etc/environment,需要重新登录或重启系统才能使更改生效。

PS:如果stable版本升级到3.5.0最新以后,后台主题和组件无法打开,建议先回滚到上一个stable版本,如V3.4.7版本,把主题先改成default后(我默认使用的是air主题),检查是否安装了discourse-category-icons这个组件,如果安装了,先删除它,然后再删除这个有问题的主题,比如我安装了AIR主题,先删除他,然后再重新安装这个AIR主题,删除docker镜像后再进行rebuild容器,这样在进入后台就可以点开主题与组件功能了。不然有可能你升级过后无法使用主题和组件功能,至少我是这么踩坑过来的,有可能是安装了类别的图标组件引起,升级到3.50后建议直接删除,因为3.50之后就不支持这个组件了,官方介绍好像是以及内置了,另外,需要注意浏览器缓存,如果不能访问,记得清理缓存或者用隐身模式打开浏览器

最后修改:2025 年 08 月 20 日
如果觉得我的文章对你有用,请随意赞赏