Run caddy 2 and admin endpoints both on the same port

1. My Caddy version (caddy -version):

v2.0.0-beta11 h1:NVHnPAdZPt6OUBMltUMe2DWVsyYRbeE6NxhCm3AjGT8=

2. How I run Caddy:

a. System environment:

Windows 10

b. Command:

caddy2_beta11_windows_amd64.exe start

c. My complete Caddyfile:

{
  "apps": {
"http": {
  "servers": {
    "srv0": {
      "listen": [
        ":2019"
      ],
      "routes": [
        {
          "handle": [
            {
              "handler": "subroute",
              "routes": [
                {
                  "handle": [
                    {
                      "handler": "rewrite",
                      "rehandle": false,
                      "strip_path_prefix": "/docker"
                    },
                    {
                      "handler": "reverse_proxy",
                      "transport": {
                        "protocol": "http",
                        "read_buffer_size": 4096,
                        "tls": {
                          "insecure_skip_verify": true
                        }
                      },
                      "upstreams": [
                        {
                          "dial": "localhost:32773"
                        }
                      ]
                    }
                  ],
                  "match": [
                    {
                      "path": [
                        "/docker"
                      ]
                    }
                  ]
                },
                {
                  "handle": [
                    {
                      "handler": "reverse_proxy",
                      "transport": {
                        "protocol": "http",
                        "read_buffer_size": 4096
                      },
                      "upstreams": [
                        {
                          "dial": "192.168.*.*:17185"
                        }
                      ]
                    }
                  ],
                  "match": [
                    {
                      "path": [
                        "/"
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  }
}
  }
}

3. The problem I’m having:

I would like to run the caddy 2 and admin endpoints both on the same port i.e 2019. The behaviour what is happening currently with the above caddy file is reverse-proxy is working fine but admin endpoints are not working as a result reload, config list and load is not working. If there is a way this can be handled.

Hi @kaushal,

Maybe you could try definiting your admin endpoint to listen on localhost:2019 so that you don’t have it clashing with the :2019 listener you’re using for your HTTP server.

Hello @Whitestrake,

I looked at the link you shared but there also it says clearly that by default admin endpoint listens on localhost:2019 so i don’t think mentioning it explicitly would make any difference.

[admin/listen](https://caddyserver.com/docs/json/admin/listen/)

The address to which the admin endpoint's listener should bind itself. Can be any single network address that can be parsed by Caddy. Default: localhost:2019

I want to use both admin endpoints and HTTP server in localhost with port 2019.

Caddy can’t serve two separate sites on the exact same host and port.

How would it know whether to serve the endpoint or whether to serve the HTTP site?

For the record, I am eventually going to look into a way to make the admin endpoint an http handler module that you can loop into one of your servers, if I can solve the cyclical shutdown problem.

I saw the related issue in GitHub, but I still don’t understand why it needs to be on the same port…

@Whitestrake @matt we have a desktop application which already uses 2 or 3 ports, addition of the caddy’s 2 ports increases utilization of ports by the single app which we want to keep to minimum as much as possible.

1 Like

Hm, I can understand wanting to minimize resources used, but it’s not uncommon for a desktop app to use dozens of ports; take a look at the ports column of Activity Monitor if you have a Mac and you’ll see what I mean. Between using 2 or 3 ports, this resource utilization is negligible, I’d be worried if Caddy was causing you to use hundreds or thousands, however.

IMO, I wouldn’t delay the construction of your app on this optimization, just use port 2019 for now and we can see about improving the situation when we get the chance. :slight_smile:

You have 65535 ports to choose from.

Pick some absurdly high port for the API, then have the Caddy server proxy HTTP requests to the high port on a subfolder or something.

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