Skip to content
Luna
Esc
↑↓navigate↵open⌘Jpreview
On this page

Use your own domain

Serve an environment's HTTP routes on a domain of your own, with a certificate Luna gets and renews.

An environment’s routes are served on a host Luna names for it. A webhook URL, an OAuth redirect or a link in an email should carry your own name, such as shop.example.com, and keep it if you ever move.

Add the domain to the environment, create two DNS records, and Luna serves the routes there over HTTPS.

Add a domain

luna domains add adds a domain to the environment and prints the DNS records to create.

luna domains add shop.example.com --env production

Without --env, the command acts on the environment that LUNA_ENV or the folder’s .env.local names, and on production when neither does. In the Console, go to the environment’s page and select Domains.

A domain is one full name, such as shop.example.com. Luna refuses a wildcard such as *.example.com, an IP address and a name under Luna’s own domain. An environment can have up to 100 domains, and a domain belongs to one environment at a time.

Create the DNS records

Create the records at your DNS provider. They look like this, with the values the command printed.

Type Name Value Does
CNAME shop.example.com The environment’s route host Sends requests to Luna, and proves the domain yours
TXT _luna.shop.example.com A token that starts with luna- Proves the domain yours

Either record proves the domain yours, but only the CNAME sends its requests to Luna. A domain at the top of its zone, such as example.com, cannot have a CNAME. Create the TXT record, and point its A records at the addresses of the CNAME’s target.

Wait for it to be verified

Luna looks for the records by itself: often in the first 10 minutes, every 2 minutes for the rest of the first day, then every 30 minutes. To look now, run luna domains verify.

luna domains verify shop.example.com --env production

luna domains list shows where each domain stands.

State Means
pending The records are not found yet. Luna does not serve the domain
verified The records prove it yours. Luna serves it and is getting a certificate
active Verified, with a certificate
failed Verified, but getting a certificate failed. Luna tries again

A pending domain shows which record is missing. verify and list take --json to print the full answer.

What the domain serves

A verified domain serves the environment’s routes and nothing else, the same as its route host. A handler called by name, at POST <LUNA_URL>/<Type>/<key>/<handler>, stays at LUNA_URL.

curl "https://shop.example.com/lists/groceries/items?key=$LUNA_KEY"

Once a domain is verified, Luna gets it a certificate and renews it when less than 30 days are left. After a failed try it waits 1 minute, then 2, then 4, up to 6 hours between tries.

Keep the records in place

Luna looks at a verified domain’s records again every 6 hours. If they no longer prove it, Luna goes on serving the domain for 3 days and says so in luna domains list.

Serve a certificate of your own

luna domains certificate serves a certificate you supply, such as one your company issues. The domain must be verified first, and the certificate must cover its name.

luna domains certificate shop.example.com --cert cert.pem --key key.pem --env production

The certificate is a PEM chain, leaf first, and the key is its private key in PEM. When it has less than 30 days left, Luna replaces it with a certificate of its own.

Domains of an added tenant

A tenant you added to an environment has routes, and so domains, of its own. Pass --tenant to act on its domains instead of the environment’s.

luna domains add acme.example.com --env production --tenant acme

Remove a domain

luna domains remove asks first, or not with --yes. Requests to the domain stop reaching the environment within seconds, and Luna deletes its certificate.

luna domains remove shop.example.com --env production

Next steps

Was this page helpful?