Reverse Proxy HTTPS & API

1. The problem I’m having:

I’d like to set up a reverse proxy as below, but I’m having trouble creating the configuration. I currently have only ever used Caddyfiles, so, while I’m open to .json configuration, it’s not something I’m familiar with.

Setup

I’m essentially attempting to host a website along with a publicly accessible API backend. I’d appreciate any help creating a configuration and knowledge on if it’s possible using a Caddyfile.

2. Error messages and/or full log output:

N/A

3. Caddy version:

v2.10.0 h1:fonubSaQKF1YANl8TXqGcn4IbIRUDdfAkpcsfI/vX5U=

4. How I installed and ran Caddy:

a. System environment:

Ubuntu Server

b. Command:

sudo apt install caddy

d. My complete Caddy config:

N/A

Caddyfile:

www.example.com {
    reverse_proxy website-container:8080
}

api.example.com {
    reverse_proxy api-container:8081
}

Thank you so much!

How would I host the endpoint on a differing port instead of a subdomain? (eg. https://example.com:8081)

Precisely like that :slightly_smiling_face:

This may help: