I can't start caddy, it says port is already used

1. The problem I’m having:

2. Error messages and/or full log output:

root@transformersagencyworkspace028432:/home/adminuser/client_setup# caddy start
2024/01/04 11:05:59.999 INFO using adjacent Caddyfile
2024/01/04 11:06:00.007 INFO admin admin endpoint started {“address”: “:2020”, “enforce_origin”: false, “origins”: [“//:2020”]}
2024/01/04 11:06:00.007 WARN admin admin endpoint on open interface; host checking disabled {“address”: “:2020”}
2024/01/04 11:06:00.007 INFO http.auto_https server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS {“server_name”: “srv0”, “https_port”: 443}
2024/01/04 11:06:00.007 INFO http.auto_https enabling automatic HTTP->HTTPS redirects {“server_name”: “srv0”}
2024/01/04 11:06:00.009 INFO http enabling HTTP/3 listener {“addr”: “:443”}
2024/01/04 11:06:00.009 INFO tls cleaning storage unit {“description”: “FileStorage:/root/.local/share/caddy”}
2024/01/04 11:06:00.009 INFO tls finished cleaning storage units
2024/01/04 11:06:00.010 INFO tls.cache.maintenance started background certificate maintenance {“cache”: “0xc00012b580”}
2024/01/04 11:06:00.010 INFO tls.cache.maintenance stopped background certificate maintenance {“cache”: “0xc00012b580”}
Error: loading initial config: loading new config: http app module: start: listen udp :443: bind: address already in use
Error: caddy process exited with error: exit status 1

Please use the preview pane to ensure it looks nice.

3. Caddy version:

v2.7.4 h1:J8nisjdOxnYHXlorUKXY75Gr6iBfudfoGhrJ8t7/flI=

4. How I installed and ran Caddy:Caddy is installed on my ubuntu server

a. System environment:

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.3 LTS
Release: 22.04
Codename: jammy

I am also running docker and using the caddy to reverse proxy the applications

b. Command: caddy start, sudo netstat -tulpn | grep :443

udp6       0      0 :::443                  :::*                                222735/caddy   
Please use the preview pane to ensure it looks nice.

c. Service/unit/compose file: docker

d. My complete Caddy config:

# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

:80 {
        # Set this path to your site's directory.
        root * /usr/share/caddy

        # Enable the static file server.

        # Another common task is to set up a reverse proxy:
        # reverse_proxy localhost:8080

        # Or serve a PHP site through php-fpm:
        # php_fastcgi localhost:9000

# Refer to the Caddy docs for more information:
# https://caddyserver.com/docs/caddyfile

Please use the preview pane to ensure it looks nice.

5. Links to relevant resources:

When you use sudo netstat -tulpn it should also print the PID/Program name. With that, you can identify which service has bound to ::443.

If you run docker, it’s probably a docker network exposed port that blocks 443.

Attached is the image of the commands i run.

root@transformersagencyworkspace028432:/home/adminuser/client_setup# sudo netstat -tulpn | grep :443
tcp6 0 0 :::443 :::* LISTEN 222735/caddy
udp6 0 0 :::443 :::* 222735/caddy

This means there is already another instance of caddy running on those ports. When you start another instance of caddy, the ports are already blocked.

Try to stop the already running caddy instance, or use “sudo kill PID”, so for example “sudo kill 222735”. Be careful with “kill” and double check the pid number. This sends a sigterm for a clean stop.

If the service is unresponsive you can send a sigkill instead of sigterm with “sudo kill -9 PID”.

If you’re on Linux and installed using a package, you should not run caddy start, and instead run Caddy as a systemd service. See Keep Caddy Running — Caddy Documentation

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