Issues creating Reverse Proxy using Caddy v2 API

1 The problem I’m having:

Please note that the API is currently exposed to everyone because I’m still testing things. The container running caddy will be turned off when not used, so if you try and make requests to it and it doesn’t work, that’s why :slight_smile:

I am trying to use the API to create a reverse proxy to proxy requests to web-01.sites.serversnow.co to 154.26.155.103:3006. I know it would be easier to use the Caddyfile to create the proxy, but eventually, this will be proxying thousands of different domains (If caddy is capable :pray:) with changes being made frequently.

Unable to save my configuration using the Rest API. My configuration also doesn’t work LOL
I’m using Docker on an Ubuntu 20.04 Server with the following docker-compose file:

services:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
      - "2019:2019"
    volumes:
      - caddy_data:/data
      - caddy_config:/config
    environment:
      - CADDY_ADMIN=0.0.0.0:2019

volumes:
  caddy_data:
  caddy_config:

The configuration Im trying to use for the API, requesting to 154.26.155.103:2019/config

{
  "apps": {
    "http": {
      "servers": {
        "srv1": {
          "listen": [":80"],
          "routes": [
            {
              "handle": [
                {
                  "handler": "reverse_proxy",
                  "upstreams": [
                    {
                      "dial": "154.26.155.103:3006"
                    }
                  ]
                }
              ],
              "match": [
                {
                  "host": ["web-01.sites.serversnow.co"]
                }
              ]
            }
          ]
        }
      }
    }
  }
}

using the cli’s caddy reverse-proxy --from web-01.sites.serversnow.co --to 154.26.155.103:3006 works fine, but it also doesn’t save and once I close the docker exec -ti root-caddy-1 shit’s back to not working.

I presume my issue with the saving is related to my docker-compose file’s volumes, but the documentation and guides are a nightmare so :person_shrugging:
Also the API documentation is even harder to follow to a :exploding_head: (brain exploding) level

2. Error messages and/or full log output:

I receive no errors from the API, No errors from the browser (apart from "This site can’t be reached")

3. Caddy version:

v2.6.4 (latest available docker image)

4. How I installed and ran Caddy:

docker compose file and docker compose up -d

a. System environment:

Ubuntu 20.04 Running Docker 24.0.2
Running API requests through Postman v10.15 (latest)

b. Command:

None, I want to use the API  

c. Service/unit/compose file:

services:
  caddy:
    image: caddy:latest
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
      - "443:443/udp"
      - "2019:2019"
    volumes:
      - caddy_data:/data
      - caddy_config:/config
    environment:
      - CADDY_ADMIN=0.0.0.0:2019

volumes:
  caddy_data:
  caddy_config:

d. My complete Caddy config:

I don't think I have one, my goal was to solely use the API because it will be frequently updated with different domains  

5. Links to relevant resources:

You should never expose the API publicly. That’s a very very bad idea.

Your config is only listening on port 80, i.e. only HTTP. Are you trying to connect with HTTPS? If so you need to change this to :443.

What is confusing exactly? (I actually don’t use Docker, so I don’t know if I can help much there for free – but I’m really curious what about our API documentation is hard to follow. I ask because I’m working on a new site and new docs.)

With the very limited information provided (“This site can’t be reached”) I suspect it has to do with your networking config more than Caddy itself.

I would highly recommend a sponsorship to support your use of Caddy at scale like this. :100: Then with the right sponsorship we can also sit down together and work out a plan to get your infrastructure up and running the best way possible.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.