Domains
Defang helps you provision SSL certificates and expose your services to the internet. You can expose your services using Defang-hosted domains or bring your own custom domain with Defang BYOC. This page explains how to configure your services to be accessible from the public internet.
Defang-hosted Domains
To make your service accessible from the public internet with Defang-hosted domains (under defang.app), you simply expose ports in your service definition.
Structure
When you deploy a publicly accessible service, Defang automatically provides you with domain names to access it.
- Playground
- BYOC
If you're deploying to the Defang Playground, you will receive:
Defang-hosted domain:
https://<username>-<service-name>--<port>.defang.dev
If you're using Defang BYOC, you will receive both:
Defang-hosted domain:
https://<service-name>--<port>.<project-name>.<username>.defang.app
Cloud provider load balancer domain (AWS example):
https://defang-xyz-b0f79bb-123456789012.ca-central-1.elb.amazonaws.com
:::tip Choosing Between Domains
- Use the Defang-hosted domain (
defang.app) for convenience and simplicity - Use the cloud provider domain (e.g., AWS ELB) if you want to avoid dependency on Defang infrastructure
- Both domains point to the same service and work identically
:::
Sample Configuration
- Compose
- Pulumi
services:
# [...]
serviceName:
ports:
- mode: ingress
target: 3000
protocol: http
As of now, the Pulumi provider does not support Defang BYOC.
const service = new defang.DefangService("serviceName", {
// [...]
ports: [{
target: 3000,
mode: "ingress",
protocol: "http",
}],
});
Bring Your Own Domain
You can also bring your own domain to a Defang project. This allows you to use your own domain name to access your services, and varies a little bit depending on your setup.
DNS Management Options
When bringing your own domain, you have two main approaches:
Option 1: Using Your Existing DNS Provider (CloudFlare, Namecheap, etc.)
If you are using Defang BYOC and do not have your domain's DNS hosted with your cloud provider, or if you are using the Defang Playground, you have two choices:
A. Point directly to your custom domain:
- Add the
domainnameto your service definition. - Run
defang compose upto deploy your project. - Run
defang cert generateto generate an SSL certificate. This command will provide instructions for where to point your domain's DNS before the certificate can be issued. - Note: The infrastructure behind your domain (e.g., the load balancer) is recreated on every
defang compose down+defang compose up, so you will need to update your DNS record and rundefang cert generateagain after each redeploy.
B. CNAME to your Defang-hosted domain (Recommended for frequent deployments):
If you frequently deploy and tear down your services (e.g., for staging environments), you can avoid reconfiguring your external DNS record each time:
- Keep the
domainnameset to your custom domain in your service definition —defang cert generateneeds it to know which hostname to issue a certificate for. - Run
defang compose upto deploy your project. - In your DNS provider, create a CNAME record pointing your custom domain to the
defang.appdomain Defang provides (e.g.,service-name--port.project-name.username.defang.app). Unlike the load balancer's domain, this one stays the same across redeploys. - Run
defang cert generateto create the SSL certificate. Note: you'll still need to run this again after eachdefang compose upto recreate the certificate — but your CNAME record won't need to change.
:::tip Managing Multiple Environments
Use the --project-name flag or the name: field in your Compose file to create separate environments. For example, a project named "hello" with --project-name hello-staging would create a separate deployment, allowing you to maintain both production and staging environments simultaneously.
:::
Option 2: Using Route 53 (AWS) - Automatic DNS Management
If you are using Defang BYOC and the DNS for your domain is hosted with your cloud provider (i.e. a Hosted Zone in Route 53, if you're using AWS), all you need to do is specify the domainname in your service definition, as in the example below.
Benefits of Route 53:
- DNS records are automatically created and updated
- SSL certificates are automatically provisioned and renewed
- No need to run
defang cert generateafter each deployment - Ideal for environments that are frequently deployed and torn down
For the time being, you can only use one domain per service. If you need to use multiple domains, please vote on this issue.
Sample Configuration
- Compose
- Pulumi
services:
# [...]
serviceName:
domainname: example.com
ports:
- mode: ingress
target: 3000
protocol: http
As of now, the Pulumi provider does not support Defang BYOC and the Defang Playground does not support bringing your own domain, since it is not for production use.
Current Support
| Provider | BYOD |
|---|---|
| AWS | ✅ |
| Azure | ✅ |
| DigitalOcean | ❌ |
| GCP | ✅ |