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

**URL:** <https://meta.discourse.org/t/integrating-discourse-caddy-and-wordpress-with-docker-ports-for-reverse-proxy/337656>\
**Category:** Self-hosting\
**Tags:** hosting\
**Created:** [November 22, 2024, 2:55am UTC](https://meta.discourse.org/t/integrating-discourse-caddy-and-wordpress-with-docker-ports-for-reverse-proxy/337656 "2024-11-22T02:55:45Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![BrianC](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/brianc/32/487568_2.png) [@BrianC](https://meta.discourse.org/u/BrianC)\
**Post date:** [November 22, 2024, 2:55am UTC](https://meta.discourse.org/t/integrating-discourse-caddy-and-wordpress-with-docker-ports-for-reverse-proxy/337656/1 "2024-11-22T02:55:45Z")

</div>

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](https://caddy.community/t/discourse-with-caddy-v2-in-docker/9244) . 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

```plaintext
apt update && apt install docker docker-compose -y

```

1. **Discourse Installed** :

- Install Discourse via the [official installation instructions](https://github.com/discourse/discourse/blob/main/docs/INSTALL-cloud.md).

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

```plaintext
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

```plaintext
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

```plaintext
expose:
  - "8880:80" # http

```

1. **Remove SSL Templates** :

yaml

Copy code

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

```

1. **Set Docker Network** :

yaml

Copy code

```plaintext
docker_args:
  - '--network caddy_net'

networks:
  caddy_net:
    external: true

```

1. **Rebuild Discourse** : Apply the changes by rebuilding the Discourse container:

bash

Copy code

```plaintext
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

```plaintext
cd /etc/docker-services

```

1. Launch the containers:

bash

Copy code

```plaintext
docker compose up -d

```

* * *

### **Step 5: Testing and Verification**

1. **Verify Running Containers** :

bash

Copy code

```plaintext
docker ps

```

1. **Access WordPress** : Navigate to:

arduino

Copy code

```plaintext
https://website.com

```

1. **Access Discourse** : Navigate to:

arduino

Copy code

```plaintext
https://forum.website.com

```

1. **Check Logs** :

- **Caddy** :

bash

Copy code

```plaintext
docker logs caddy

```

- **Discourse** :

bash

Copy code

```plaintext
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

```plaintext
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

```plaintext
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.

---

_[View the full topic](https://meta.discourse.org/t/integrating-discourse-caddy-and-wordpress-with-docker-ports-for-reverse-proxy/337656)._
