Use of Locahost causes caddy to start on :80

1. My Caddy version (caddy version):

V2
fbd9515

2. How I run Caddy:

caddy run

a. System environment:

windows 10

b. Command:


d. My complete Caddyfile or JSON config:

Caddyfile with Localhost

localhost:16655 {

        log {
          output file d:\caddy\access564.log
        }

        respond "this is a caddy2 server"

  }

adapt json

{
  "logging": {
    "logs": {
      "log0": {
        "writer": {
          "filename": "d:\\caddy\\access564.log",
          "output": "file"
        },
        "include": [
          "http.log.access.log0"
        ]
      }
    }
  },
  "apps": {
    "http": {
      "servers": {
        "srv0": {
          "listen": [
            ":16655"
          ],
          "routes": [
            {
              "match": [
                {
                  "host": [
                    "localhost"
                  ]
                }
              ],
              "handle": [
                {
                  "handler": "subroute",
                  "routes": [
                    {
                      "handle": [
                        {
                          "body": "this is a caddy2 server",
                          "handler": "static_response"
                        }
                      ]
                    }
                  ]
                }
              ],
              "terminal": true
            }
          ],
          "logs": {
            "logger_names": {
              "localhost:16655": "log0"
            }
          }
        }
      }
    }
  }
}

without localhost


:16655 {

        log {
          output file d:\caddy\access564.log
        }

        respond "this is a caddy2 server"

  }

adapt json

{
  "logging": {
    "logs": {
      "log0": {
        "writer": {
          "filename": "d:\\caddy\\access564.log",
          "output": "file"
        },
        "include": [
          "http.log.access.log0"
        ]
      }
    }
  },
  "apps": {
    "http": {
      "servers": {
        "srv0": {
          "listen": [
            ":16655"
          ],
          "routes": [
            {
              "handle": [
                {
                  "body": "this is a caddy2 server",
                  "handler": "static_response"
                }
              ]
            }
          ],
          "logs": {
            "logger_names": {
              ":16655": "log0"
            }
          }
        }
      }
    }
  }
}

3. The problem I’m having:

If I load the caddyfile with localhost:16655 I get an error as port 80 is in use. If I just use a caddyfile without localhost and just :16655 , it works fine.

4. Error messages and/or full log output:

D:\caddy>curl localhost:2019/load -X POST -H "Content-Type: application/json" -d @caddyfile_withlocalhost.json
{"error":"loading config: loading new config: http app module: start: tcp: listening on :80: listen tcp :80: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted."}

Answered here:

1 Like

http_port does not work in Caddy 2.

The following Caddyfile reproduces the problem:

localhost:8001 {
reverse_proxy localhost:8000
}

I believe the expected behaviour of your given Caddyfile is:

  • Serve localhost via HTTPS on port 8001
  • Redirect regular HTTP on the default port (80) to the specified port

Try serving explicitly HTTP, e.g. http://localhost:8001

1 Like

Cheers! Thanks a lot.

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