How do I Generate a Self-signed Certificate using a domain name?

1. The problem I’m having:

I don’t have a dns server available, so I appended a mapping to the hosts file for testing purposes.
like this:
So I want to use caddy to generate a self-signed certificate for
But when I wrote the domain name in the caddyfile it applied for the publicly trusted certificate. for example through Let’s Encrypt.
But i want to generate by…

I have seen in the documentation that tls internal is used.
But I don’t have a good understanding of it, and I might need an example that looks like my scenario.


2. Error messages and/or full log output:

no error, just a question of usage

3. Caddy version:

v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=

4. How I installed and ran Caddy:

  • Use the official binary file
    Edit Caddyfile
    caddy run

a. System environment:

Centos7 x86_64

b. Command:

caddy run

c. Service/unit/compose file:

Did not use

d. My complete Caddy config:


5. Links to relevant resources:


This is what you want: {
	tls internal
1 Like