下载环境文件

wget -O .env https://raw.githubusercontent.com/chatwoot/chatwoot/develop/.env.example

下载docker compose 文件

wget -O docker-compose.yaml https://raw.githubusercontent.com/chatwoot/chatwoot/develop/docker-compose.production.yaml

修改 .env 配置

如果数据库和redis端口和密码有变化,也需要这里配置。同时配置 docker-compose.yaml 修改端口和密码。

vim .env
# 主要修改秘钥,前置网站地址,和语言。
SECRET_KEY_BASE=72e10fb22689bc53
FRONTEND_URL=https://chat.defile.cc
DEFAULT_LOCALE=zh_CN

vim docker-compose.yaml

配置端口号,密码,和持久化到硬盘。

  postgres:
    image: postgres:12
    restart: always
    ports:
      - '127.0.0.1:5432:5432'
    volumes:
      - /data/postgres:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=chatwoot
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres

初始化数据库

docker compose run –rm rails bundle exec rails db:chatwoot_prepare

启动

docker compose up -d

测试是否启动

curl -I localhost:3000/api

配置 nginx ,这步很重要,不能缺少。

nginx的重点两个配置。

1. 启用 headers 里的下划线参数

underscores_in_headers on;

2. 启动 websocket 反向代理

proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection “upgrade”;

完整的 nginx 配置信息例子

server {
  server_name <yourdomain.com>;

  # Point upstream to Chatwoot App Server
  set $upstream 127.0.0.1:3000;

  # Nginx strips out underscore in headers by default
  # Chatwoot relies on underscore in headers for API
  # Make sure that the config is set to on.
  underscores_in_headers on;
  location /.well-known {
    alias /var/www/ssl-proof/chatwoot/.well-known;
  }

  location / {
    proxy_pass_header Authorization;
    proxy_pass http://$upstream;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Ssl on; # Optional

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_buffering off;

    client_max_body_size 0;
    proxy_read_timeout 36000s;
    proxy_redirect off;
  }
  listen 80;
}