Tcp 127.0.0.1:2019: bind: address already in use

Hi, i have a problem with caddy api endpoint. I changed the port of end point to 0.0.0.0:2019 for remote connection. then i give permittion for only spesific ips can be use it. everything works fine only i have when i post to 0.0.0.0/load

1. Caddy version (caddy version):

Caddy v2.2.1

2. How I run Caddy:

sudo systemctl start caddy

a. System environment:

ubuntu 18.04

d. My complete Caddyfile or JSON config:

{
  "apps": {
    "http": {
      "servers": {
        "srv0": {
          "listen": [
            ":443"
          ],
          "write_timeout": "10s",
          "idle_timeout": "10s",
          "read_header_timeout": "10s",
          "read_timeout": "10s",
          "max_header_bytes": "100000000",
          "routes": [
            {
              "handle": [
                {
                  "handler": "subroute",
                  "routes": [
                    {
                      "handle": [
                        {
                          "handler": "vars",
                          "root": "/path/to/frontend/"
                        }
                      ]
                    },
                    {
                      "handle": [
                        {
                          "handler": "reverse_proxy",
                          "upstreams": [
                            {
                              "dial": "unix//path/to/sockfile.sock"
                            }
                          ]
                        }
                      ],
                      "match": [
                        {
                          "not": [
                            {
                              "path": [
                                "/static*"
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ],
              "match": [
                {
                  "host": [
                    "domain.tdl"
                  ]
                }
              ],
              "terminal": true
            }
          ]
        }
      }
    }
  }
}

3. The problem I’m having:

When i post load new config for reset all caddy config i got error

4. Error messages and/or full log output:

{"error":"loading config: loading new config: starting caddy administration endpoint: listen tcp 127.0.0.1:2019: bind: address already in use"}
i am posting via curl command for testing.
command are bellow
curl -X POST "http://0.0.0.0:2019/load" \
	-H "Content-Type: application/json" \
	-d '{
  "apps": {
    "http": {
      "servers": {
        "srv0": {
          "listen": [
            ":443"
          ],
          "write_timeout": "10s",
          "idle_timeout": "10s",
          "read_header_timeout": "10s",
          "read_timeout": "10s",
          "max_header_bytes": "100000000",
          "routes": [
            {
              "handle": [
                {
                  "handler": "subroute",
                  "routes": [
                    {
                      "handle": [
                        {
                          "handler": "vars",
                          "root": "/path/to/frontend/"
                        }
                      ]
                    },
                    {
                      "handle": [
                        {
                          "handler": "reverse_proxy",
                          "upstreams": [
                            {
                              "dial": "unix//path/to/sockfile.sock"
                            }
                          ]
                        }
                      ],
                      "match": [
                        {
                          "not": [
                            {
                              "path": [
                                "/static*"
                              ]
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ],
              "match": [
                {
                  "host": [
                    "domain.tdl"
                  ]
                }
              ],
              "terminal": true
            }
          ]
        }
      }
    }
  }
}'

Thank you

Where? I’m not seeing that in the configs you posted.

listen tcp 127.0.0.1:2019: bind: address already in use

This error happens when the OS can’t listen on the address because the socket is already in use. Make sure other Caddy instances aren’t running and that your config is correct.

Oh, sorry Matt i forgot add Caddyfile
( when i restart machine first read config from Caddyfile then my app post to /loads json config. )

{
    # debug
    admin 0.0.0.0:2019
}

(redirect) {
        @http {
                protocol http
        }
        redir @http https://{hostport}{uri} 302
}

domain.tdll {
  reverse_proxy @notStatic unix//path/to/sockfile.sock
  log {
      level DEBUG
      output file /path/to/caddy.log
      format single_field common_log
  }
  @notStatic {
      not {
          path /static*
      }
  }
  root * /path/to/root
}

Thanks. So it seems that your system won’t let you bind two sockets to 0.0.0.0:2019 and 127.0.0.1:2019 – it’s possible that internally it reads 0.0.0.0 as the loopback interface for IPv4, which is 127.0.0.1, which is probably configurable on the system, but to be honest I would not know without some searching. I’d look into that first; but the good news is it’s not a Caddy problem so it’s something that you can fix on your end!

2 Likes

Hi Matt,
thank you for your answer, It make it easy to found solution
i changed port to 2020 from 2019 end its worked. i think port 2019 bussy. maybe i have to kill all 2019 port process, but i didn’t try it. its now working :slight_smile:

# Caddyfile
{
    admin 0.0.0.0:2020
}

Thank you again.

1 Like

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