Integrating Discourse, Caddy, and WordPress with Docker Ports for Reverse Proxy

This is my first post and wanted to provide a guide I made with our friend ChatGPT after struggling for days to figure out how to get Caddy working for reverse proxy for Discourse installed with the office instructions. I used info I found on Caddy’s forum here. Caddy Discourse Setup . This may be straight forward but for those of us just getting started with Discourse a bit of a lift to get it going.

Thanks for an obviously great community.

Integrating Discourse, Caddy, and WordPress with Docker Ports for Reverse Proxy


Overview

This guide provides a step-by-step process to set up Discourse with Caddy as a reverse proxy, alongside a WordPress installation, using Docker Compose. These instructions are designed for a typical Ubuntu 22 LTS server and demonstrate how to integrate multiple services while ensuring a clean and reproducible setup.


Prerequisites

Ensure the following prerequisites are met before proceeding:

  1. Docker and Docker Compose:

bash

Copy code

apt update && apt install docker docker-compose -y
  1. Discourse Installed:
  1. Domain Names:
  • A primary domain for WordPress (e.g., website.com).
  • A subdomain for Discourse (e.g., forum.website.com).

Step 1: Configuring docker-compose.yml

The docker-compose.yml file defines services for Caddy (reverse proxy), WordPress, and MySQL.

File Location

Save the file as /etc/docker-services/docker-compose.yml.

Configuration

yaml

Copy code

version: '3.8'

services:
  caddy:
    image: caddy:latest
    container_name: caddy
    restart: always
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config
    networks:
      - caddy_net

  wordpress:
    image: wordpress:latest
    container_name: wordpress
    restart: unless-stopped
    environment:
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: example_user
      WORDPRESS_DB_PASSWORD: example_password
      WORDPRESS_DB_NAME: example_db
    volumes:
      - ./wordpress:/var/www/html
    networks:
      - caddy_net

  db:
    image: mysql:5.7
    container_name: wordpress_db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: example_password
      MYSQL_DATABASE: example_db
      MYSQL_USER: example_user
      MYSQL_PASSWORD: example_password
    volumes:
      - db_data:/var/lib/mysql
    networks:
      - caddy_net

volumes:
  caddy_data:
  caddy_config:
  db_data:

networks:
  caddy_net:
    external: true

Step 2: Setting Up the Caddy Reverse Proxy

Caddy proxies requests to both Discourse and WordPress and manages HTTPS certificates.

File Location

Save the configuration as /etc/docker-services/Caddyfile.

Configuration

caddyfile

Copy code

website.com {
    reverse_proxy wordpress:80
}

forum.website.com {
    reverse_proxy app:80
}

This configuration ensures:

  • Requests to website.com are proxied to the WordPress container.
  • Requests to forum.website.com are proxied to the Discourse container.

Step 3: Configuring Discourse

Update app.yml to integrate Discourse with Caddy and the Docker network.

File Location

Located in /var/discourse/containers/app.yml.

Configuration Changes

  1. Expose Non-Standard HTTP Ports:

yaml

Copy code

expose:
  - "8880:80"   # http
  1. Remove SSL Templates:

yaml

Copy code

# - "templates/web.ssl.template.yml"
# - "templates/web.letsencrypt.ssl.template.yml"
  1. Set Docker Network:

yaml

Copy code

docker_args:
  - '--network caddy_net'

networks:
  caddy_net:
    external: true
  1. Rebuild Discourse: Apply the changes by rebuilding the Discourse container:

bash

Copy code

cd /var/discourse
./launcher rebuild app

Step 4: Deploy the Services

Start the Docker services for Caddy and WordPress:

  1. Navigate to the Docker Compose directory:

bash

Copy code

cd /etc/docker-services
  1. Launch the containers:

bash

Copy code

docker compose up -d

Step 5: Testing and Verification

  1. Verify Running Containers:

bash

Copy code

docker ps
  1. Access WordPress: Navigate to:

arduino

Copy code

https://website.com
  1. Access Discourse: Navigate to:

arduino

Copy code

https://forum.website.com
  1. Check Logs:
  • Caddy:

bash

Copy code

docker logs caddy
  • Discourse:

bash

Copy code

tail -f /var/discourse/shared/standalone/log/rails/production.log

Troubleshooting

  1. Discourse Not Responding:
  • Ensure Discourse is bound to port 8880.
  • Verify the container is connected to caddy_net:

bash

Copy code

docker network inspect caddy_net
  1. Caddy SSL Errors:
  • Check Caddy’s certificate logs in /data.
  1. Rebuild Issues:
  • Ensure the caddy_net network is active when rebuilding Discourse:

bash

Copy code

docker network ls

Conclusion

This guide demonstrates how to integrate Discourse, Caddy, and WordPress using Docker Compose and a reverse proxy configuration. By following these steps, you can achieve a modular and secure setup for your own website infrastructure.

You used an Arduino for this?