How to configure caddy to only be accessed through a domain name?

1. Caddy version:

2.6.2

2. How I installed, and run Caddy:

apt install caddy
caddy run

a. System environment:

ubuntu 20.04
systemd

b. Command:

caddy run
Paste command here.

c. Service/unit/compose file:

Paste full file contents here.
Make sure backticks stay on their own lines,
and the post looks nice in the preview pane.

d. My complete Caddy config:

Paste your config here, replacing this text.
Use `caddy fmt` to make it readable.
DO NOT REDACT anything except credentials.
LEAVE DOMAIN NAMES INTACT.
Make sure the backticks stay on their own lines.

ha.smart-iot.ga {
	encode gzip
	tls /etc/letsencrypt/live/smart-iot.ga/fullchain.pem /etc/letsencrypt/live/smart-iot.ga/privkey.pem
	reverse_proxy http://ha.smart-iot.ga:8033
}

za.smart-iot.ga {
	encode gzip
	tls /etc/letsencrypt/live/smart-iot.ga/fullchain.pem /etc/letsencrypt/live/smart-iot.ga/privkey.pem
	reverse_proxy localhost:8080
}

3. The problem I’m having:

How to configure caddyfile to only be accessed through a domain name?And disable IP address access to server?

4. Error messages and/or full log output:

Paste logs/commands/output here.
USE THE PREVIEW PANE TO MAKE SURE IT LOOKS NICELY FORMATTED.

5. What I already tried:

6. Links to relevant resources:

I’m not sure I understand your question.

You’re already using a domain name in your Caddyfile to route traffic. Caddy won’t handle requests unless they specify a hostname that matches your config.

Please elaborate. Show what behaviour you’re seeing. Use curl -v to make example requests. You haven’t shown us your logs.

What I mean is that I want to prohibit access to my website by IP, only by domain name (domain name access is normal now), what should I do to prohibit access by ip?

I think there’s a misunderstanding of how networking works in general.

If someone can connect by domain, they have to be able to connect by IP. Because a domain is just a name that gets resolved via DNS to an IP address.

You’ll need to be more specific about what you want to prevent, and why.

1 Like