Multiple sites with same domain and different ports

1. Caddy version (caddy version):

v2.3.0 h1:fnrqJLa3G5vfxcxmOH/+kJOcunPLhSBnjgIvjXV/QTA=

2. How I run Caddy:

Installed with apt-get install caddy and using the default service config (see below)

a. System environment:

Ubuntu 20.04

b. Command:

sudo systemctl start caddy

c. Service/unit/compose file:

# /lib/systemd/system/caddy.service
# caddy.service
#
# For using Caddy with a config file.
#
# Make sure the ExecStart and ExecReload commands are correct
# for your installation.
#
# See https://caddyserver.com/docs/install for instructions.
#
# WARNING: This service does not use the --resume flag, so if you
# use the API to make changes, they will be overwritten by the
# Caddyfile next time the service is restarted. If you intend to
# use Caddy's API to configure it, add the --resume flag to the
# `caddy run` command or use the caddy-api.service file instead.

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

{
        debug
}

http://chatdev.blackjackapprenticeship.com:8088 {
	reverse_proxy localhost:3039
}

https://chatdev.blackjackapprenticeship.com {
	reverse_proxy localhost:3000
}

3. The problem I’m having:

My apps are running correctly on localhost (i.e. I can curl localhost:3000 and localhost:3039 without issue). However, only the default ports (80/443) are returning anything when I run with the above Caddyfile. Why can I not get a response on port 8088 of my domain?

$ curl -v http://chatdev.blackjackapprenticeship.com:8088
*   Trying 52.89.109.217:8080...
* TCP_NODELAY set

And it just hangs there until it times out.

4. Error messages and/or full log output:

From `sudo journalctl -u caddy.service

-- Logs begin at Sun 2021-09-12 01:31:54 UTC. --
Sep 26 08:13:38 ip-172-31-45-81 caddy-with-cloudflare[102200]: {"level":"info","ts":1632644018.6345642,"logger":"http","msg":"enabling automatic TLS certificate management","domains":["chatdev.blackjackapprenticeship.com"]}
Sep 26 08:13:38 ip-172-31-45-81 caddy-with-cloudflare[102200]: {"level":"debug","ts":1632644018.6350524,"logger":"tls","msg":"loading managed certificate","domain":"chatdev.blackjackapprenticeship.com","expiration":1640410680,"issuer_key":"acme-v02.api.letsencrypt.org-directory","storage":"FileStorage:/var/lib/caddy/.local/share/caddy"}
Sep 26 08:13:38 ip-172-31-45-81 caddy-with-cloudflare[102200]: {"level":"info","ts":1632644018.6396008,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0002c4310"}
Sep 26 08:13:38 ip-172-31-45-81 caddy-with-cloudflare[102200]: {"level":"info","ts":1632644018.6464748,"msg":"autosaved config","file":"/var/lib/caddy/.config/caddy/autosave.json"}
Sep 26 08:13:38 ip-172-31-45-81 caddy-with-cloudflare[102200]: {"level":"info","ts":1632644018.6466293,"msg":"serving initial configuration"}
Sep 26 08:13:38 ip-172-31-45-81 caddy-with-cloudflare[102200]: {"level":"info","ts":1632644018.6476276,"logger":"tls","msg":"cleaned up storage units"}

5. What I already tried:

I’ve tried variations of the address for my first block. It works fine if I use http://localhost:8088 or any other domain, but not the same domain as the second block and I’m restricted on this project to using the same domain. I’ve tried specifying ports explicitly on both like this:

http://chatdev.blackjackapprenticeship.com:8088 {
	reverse_proxy localhost:3039
}

https://chatdev.blackjackapprenticeship.com:443 {
	reverse_proxy localhost:3000
}

I’ve tried reading through a number of forum posts and documentation from Caddy that all suggest this should work without issue (see One domain multiple ports).

I’m at a loss and any help is appreciated.

6. Links to relevant resources:

Are you sure you have port 8088 forwarded to your server, and open on any firewalls?

Your Caddyfile looks fine. It’s most likely to be a networking configuration issue.

Please upgrade to v2.4.5!

1 Like

Mea culpa! And thank you very much for pointing out my mistake so kindly!

It was indeed an EC2 networking error on my end for not allowing traffic.

2 Likes

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