一个只会对着文档安装的小白
欢迎大神进群交流

自定义安装Discourse与其他网站程序共存

discourse是一个开源的论坛程序,官方提供了一个非常方便的安装工具:discourse-setup。

discourse-setup在一定程度上降低了discourse的搭建难度,但也有一些问题存在。

例如一台服务器如果你使用discourse-setup,那么这台服务器就不能再运行其他的网站了,因为discourse-setup默认将使用80、443端口来运行discourse。除此之外,一些更细粒度的配置无法通过discourse-setup完成,比如修改文件上传大小等。

为解决上述问题,这篇文章记录一下自定义安装Discourse的步骤。

安装需要用到的软件包:

apt -y update   apt -y install curl git nginx python3-certbot-nginx  curl -fsSL https://get.docker.com -o get-docker.sh  sh get-docker.sh

克隆discourse_docker项目:

git clone https://github.com/discourse/discourse_docker.git /var/discourse  cd /var/discourse

复制配置文件并编辑:

cp samples/standalone.yml containers/app.yml  nano containers/app.yml

注释掉如下配置模板:

#- "templates/web.ssl.template.yml"  #- "templates/web.letsencrypt.ssl.template.yml"

增加如下配置模板:

- "templates/web.socketed.template.yml"

注释掉暴露的80、443端口:

#expose:  #  - "80:80"  #  - "443:443"

如果需要修改文件上传大小,在params下面增加如下配置:

params:    upload_size: "100m"

接着修改如下配置,你需要事先准备好一个smtp服务器:

DISCOURSE_HOSTNAME: 'discourse.example.com'  DISCOURSE_DEVELOPER_EMAILS: '[email protected]'  DISCOURSE_SMTP_ADDRESS: mx1.example.com  DISCOURSE_SMTP_PORT: 587  DISCOURSE_SMTP_USER_NAME: [email protected]  DISCOURSE_SMTP_PASSWORD: password  DISCOURSE_NOTIFICATION_EMAIL: [email protected]

使用刚才的配置创建discourse容器:

./launcher bootstrap app

新建nginx配置:

nano /etc/nginx/sites-available/discourse

写入如下配置:

server {      listen 80;      server_name discourse.example.com;      client_max_body_size 100m;        location / {          proxy_pass http://unix:/var/discourse/shared/standalone/nginx.http.sock:;          proxy_set_header Host $http_host;          proxy_http_version 1.1;          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;          proxy_set_header X-Forwarded-Proto $scheme;          proxy_set_header X-Real-IP $remote_addr;      }  }

启用新的nginx配置:

ln -s /etc/nginx/sites-available/discourse /etc/nginx/sites-enabled/discourse

签发SSL证书

certbot --nginx

打开网站创建管理员账号,接下来还需要在管理员后台启用force https:

自定义安装Discourse与其他网站程序共存

这一步是必须的,如果不做的话,你打开浏览器的控制台看看,会有很多混合内容的警告和报错。

在之前我们通过app.yml设置了文件上传大小,还需要在后台设置max attachment size才能生效:

自定义安装Discourse与其他网站程序共存

可以和上图内一样通过设置authorized extensions for staff来允许管理员上传其他格式的文件,这个设置仅影响管理员,普通用户依旧受authorized extensions限制。

一点补充:

这套配置也适用于现有安装,你可以先停止运行discourse:

cd /var/discourse  ./launcher stop app

之后按照文本的配置修改好app.yml后重新创建容器即可:

./launcher rebuild app

以下是launcher的所有用法:

Usage: launcher COMMAND CONFIG [--skip-prereqs] [--docker-args STRING]  Commands:      start:       Start/initialize a container      stop:        Stop a running container      restart:     Restart a container      destroy:     Stop and remove a container      enter:       Open a shell to run commands inside the container      logs:        View the Docker logs for a container      bootstrap:   Bootstrap a container for the config based on a template      run:         Run the given command with the config in the context of the last bootstrapped image      rebuild:     Rebuild a container (destroy old, bootstrap, start new)      cleanup:     Remove all containers that have stopped for > 24 hours      start-cmd:   Generate docker command used to start container
赞(0)
未经允许不得转载:PEAKM BLOG » 自定义安装Discourse与其他网站程序共存

评论 抢沙发

登录

找回密码

注册