443 Address already in use, even though stopped

1. Output of caddy version:

v2.6.1 h1:EDqo59TyYWhXQnfde93Mmv4FJfYe00dO60zMiEt+pzo=

2. How I run Caddy:

CLI Putty via SSHiing into server

a. System environment:

linux, Debian 8

b. Command:

sudo service caddy stop
sudo service caddy start
systemctl status caddy.service

d. My complete Caddy config:

`caddy fmt`

# This replaces the existing content in /etc/caddy/Caddyfile

# A CONFIG SECTION FOR YOUR HOSTNAME

foundry.billsiauw.com {
    # PROXY ALL REQUEST TO PORT 30000
    reverse_proxy localhost:30000
    encode zstd gzip
}

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

3. The problem I’m having:

I’m trying to use caddy to reverse proxy to the domain mentioned in my caddy file. The issue I’m encountering is that I can’t seem to restart caddy after modifying the caddy file. Running the systemctl status caddy.service command seems to suggest that the port 443 is already being used, but trying to stop caddy via sudo service caddy stop doesn’t seem to help solve this problem

4. Error messages and/or full log output:

Results from running sudo service caddy start or sudo service caddy reload:

Job for caddy.service failed. See 'systemctl status caddy.service' and 'journalctl -xn' for details.

Results from subseuqently running systemctl status caddy.service after either of these:

● caddy.service - Caddy
   Loaded: loaded (/lib/systemd/system/caddy.service; enabled)
   Active: failed (Result: exit-code) since Tue 2022-10-04 22:54:01 PDT; 1min 56s ago
     Docs: https://caddyserver.com/docs/
  Process: 27493 ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile (code=exited, status=1/FAILURE)
 Main PID: 27493 (code=exited, status=1/FAILURE)
   Status: "loading new config: http app module: start: tcp: listening on :443: listen tcp :443: bind: address already in use"

Results from running journalctl -xn:

-- Logs begin at Wed 2022-07-20 19:18:40 PDT, end at Mon 2022-09-26 08:33:01 PDT. --
Sep 26 08:32:57 red snmpd[631]: error on subcontainer 'ia_addr' insert (-1)
Sep 26 08:32:57 red named[2875]: client 74.125.181.133#46850 (ns2.mido.tv): query (cache) 'ns2.mido.tv/A/IN' denied
Sep 26 08:32:59 red snmpd[631]: error on subcontainer 'ia_addr' insert (-1)
Sep 26 08:32:59 red named[2875]: client 172.71.153.63#48324 (talhodan.com): query (cache) 'talhodan.com/DNSKEY/IN' denied
Sep 26 08:33:00 red snmpd[631]: error on subcontainer 'ia_addr' insert (-1)
Sep 26 08:33:00 red named[2875]: client 172.69.21.93#56248 (talhodan.com): query (cache) 'talhodan.com/A/IN' denied
Sep 26 08:33:00 red named[2875]: client 172.253.1.4#48820 (talhodan.com): query (cache) 'talhodan.com/NS/IN' denied
Sep 26 08:33:00 red named[2875]: client 172.253.0.5#50473 (ns2.mido.tv): query (cache) 'ns2.mido.tv/AAAA/IN' denied
Sep 26 08:33:01 red named[2875]: client 172.253.1.5#55185 (ns2.mido.tv): query (cache) 'ns2.mido.tv/A/IN' denied
Sep 26 08:33:01 red named[2875]: client 162.158.165.68#18194 (talhodan.com): query (cache) 'talhodan.com/DNSKEY/IN' denied

Also, interestingly enough, when I tried verifying my caddyfile via caddy validate, it seems like there is an issue with the file:

Error: decoding config: unexpected end of JSON input

I can’t quite tell what the issue is, and from referencing documentation it seems fine?

5. What I already tried:

I’ve tried restarting and reloading caddy, as well as stopping it before running the commands again, but those don’t quite seem to remedy the issues I have encountered. I was initially using commands without the sudo service prefix, but I came across a post of someone who had a similar issue to me on Debian, and was suggested to use these commands instead. The original poster of that topic was using Cloudflare however, which I am not.

6. Links to relevant resources:

Following through this install guide / tutorial: Install — Caddy Documentation
The post I referenced: Port 443 is already in use?

Are you sure you don’t have some other webserver running, like Apache or Nginx, using that port?

You can run this to see what’s bound to port 443:

netstat -ltnp | grep :443
1 Like

I’m not too familiar with that command, this is the output that occurs when I run it. Does this mean the port’s being used at the moment?

Yeah that means you have httpd running (which is Apache) taking up port 443. You need to stop that service, so that Caddy can run.

Hmm, is there a way for me to change the port caddy runs on? I might have missed something the documentation, but I couldn’t find anything about doing so?

You must use port 80 and 443 with Caddy so that it can automate TLS issuance.

Port 443 is the default HTTPS port. If you use a different port, then your users would have to type the port number in their browser every time.

If you still need Apache running, then instead, you should configure Apache to use a different port, then have Caddy proxy requests you need to serve with Apache to that port.

3 Likes

Oh I see, thanks for that info! I was able to get it working by switching Apache to a different port. Thanks for the help!

2 Likes

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