# Connecting Your Own Domain

In this article, we will explain in detail how to connect your own domain to the Tuna platform and publish a local website to the internet without a public IP, complex network configurations like VPN, and without deploying code to any server or hosting.

Publishing on your own domain can be interesting for Demo stands when you present a solution to a client. The client sees a finished solution while you haven't spent a minute on environment preparation, and you can also fix small things on the fly. However, there can be many more use cases.

## Connecting a Domain

### Purchasing a Domain

First, you'll need your own domain (if you don't have one). You can buy it, for example, from [Reg.ru](https://www.reg.ru/?utm_source=tuna.am) or [namecheap](https://www.namecheap.com/?utm_source=tuna.am) or any other domain registrar. For examples in this article, we use the domain `tuna-dev.ru`.

### Connecting to Tuna and Getting Settings

Go to the [domain management page](https://my.tuna.am/domains) in your personal account and click **Add domain** in the top right corner.

![](/docs/img/connect-self-domain/add-domain.png)

Select the **Own domain** type and enter your domain in the **Domain** field. In our case, it's `api.tuna-dev.ru`. If you have a Unicode domain, for example in one of these zones `.РФ, .ДЕТИ, .ҚАЗ`, you need to specify the converted [punycode](https://www.reg.ru/web-tools/punycode?utm_source=tuna.am) variant.

![](/docs/img/connect-self-domain/adding-in-my.png)

After specifying your domain, you will see the required DNS settings.

### DNS Configuration

Go to the DNS records management panel and create the record shown in the dashboard. For a subdomain like `api.tuna-dev.ru`, this is a **CNAME**: it points to the Tuna infrastructure as a whole rather than to a specific server, so the domain works with [fault tolerance](https://tuna.am/en/blog/high-availability.md). An apex domain like `tuna-dev.ru` can't be connected with a CNAME; there is a [separate option](#apex) for it. If you have an **AAAA** record specified for the selected domain, it needs to be deleted, as IPv6 is not currently supported.

![](/docs/img/connect-self-domain/add-cname.png)

### Waiting for Confirmation

After creating the DNS record, you can return to your personal account and click **Add**. The domain will enter verification mode.

![](/docs/img/connect-self-domain/check-status.png)

Validation usually takes from 15 minutes to 2 hours but can extend to a couple of days, depending on the DNS record TTL. The verification process is limited to **24 hours** and is divided into 2 main stages:

* **DNS Check** - we verify that your domain is configured correctly
* **TLS Check** - we issue a [Let's Encrypt](https://letsencrypt.org/?utm_source=tuna.am) certificate for your domain

If the addition process failed with a DNS error, [check](https://www.reg.ru/nettools/dig?utm_source=tuna.am) that you correctly created the DNS record and it points to the correct server. If everything is correct, the DNS cache may not have updated yet and you need to wait, then simply resume the verification. If the addition process failed with a TLS error, check if there are obvious errors in the DNS configuration: AAAA records, recursively looped pointers. If you can't figure it out yourself, contact [support](mailto:info@tuna.am).

### Usage

After successful domain verification, you will receive a notification email.

![](/docs/img/connect-self-domain/domain-verified.png)

Now you can start using it. To do this, add the `--domain` flag or its short variant `-d` or an [environment variable](https://tuna.am/en/docs/guides/environment-variables.md) and your domain to the `tuna http <your_port>` command, for example:

```shell
tuna http 8080 --domain=api.tuna-dev.ru

```

```shell
tuna http 8080 -d api.tuna-dev.ru

```

```shell
export TUNA_DOMAIN=api.tuna-dev.ru
tuna http 8080

```

## Apex Domain

An apex domain is the domain itself without a subdomain: `example.com`, not `www.example.com`. DNS rules don't allow a CNAME on it, only A records pointing to specific addresses. Such a domain works, but without fault tolerance: if one of the addresses changes or becomes unavailable, some visitors won't be able to open the site.

That's why, when you add an apex domain, the dashboard asks you to choose how to connect it.

### Site on a Subdomain, with Fault Tolerance

This is the option we recommend. The tunnel runs on a subdomain: `www.example.com` by default, but you can choose your own, for example `shop.example.com`. The subdomain is connected with a CNAME, the apex with A records. Once both domains pass the DNS check, Tuna creates a [gateway](https://tuna.am/en/docs/gateways.md) with a permanent redirect (code 308) from `example.com` to the subdomain. The page path is kept: `example.com/catalog` opens `www.example.com/catalog`.

![The form for adding an apex domain with the Site on a subdomain, with fault tolerance option selected](/docs/img/connect-self-domain/apex-create-site.webp)

After you add the domain, the dashboard shows the DNS records for both domains and the command to start a tunnel on the subdomain:

![The New domains window: a CNAME record for www.example.com and A records for example.com](/docs/img/connect-self-domain/apex-created.webp)

```shell
tuna http 8080 --domain=www.example.com

```

Once both domains pass the check, the apex in the list gets a redirect mark:

![The domain list: example.com redirects to www.example.com](/docs/img/connect-self-domain/apex-list.webp)

The pair of domains takes two slots in your custom domain limit. If only one slot is free, the subdomain option is unavailable, and a link to upgrade your subscription appears next to it.

What to know about the redirect:

* The query string isn't kept on redirect: `example.com/catalog?utm_source=mail` opens `www.example.com/catalog`. Point links with UTM tags straight to the subdomain.
* The redirect gateway is visible in the [Gateways](https://my.tuna.am/gateways) section. If you delete it, the redirect turns off, and the apex domain card gets a button to turn it back on.
* While the gateway runs on the apex, a tunnel on `example.com` won't start: the server responds with `Domain already reserved by gateway`.
* If you delete the subdomain, the apex gateway stays and keeps redirecting to the deleted address. Delete it manually in the **Gateways** section.

### Apex Domain Only

The apex is connected with A records to every address of the [cell](https://tuna.am/en/docs/guides/corporate-network.md#firewall-addresses), and the tunnel runs on `example.com`. Such a domain has no fault tolerance, and the dashboard warns you about it.

![The form for adding an apex domain with the example.com only option selected and marked as having no fault tolerance](/docs/img/connect-self-domain/apex-only.webp)

### How to Migrate an Already Connected Domain

Apex domains connected earlier and subdomains on A records are marked with a warning icon in the list.

![The domain list: a warning icon next to the status of example.com](/docs/img/connect-self-domain/apex-warning.webp)

For an apex domain, the card has a step-by-step migration:

1. **Add a subdomain for the site.** The dashboard shows the CNAME record to create at your registrar.
2. **Start the tunnel on the subdomain** instead of the apex. Stop the tunnel on the apex: while it runs, the redirect won't turn on.
3. **Turn on the redirect to the subdomain.** The button becomes available once the subdomain passes the DNS check. The redirect starts working in about a minute.

![The apex domain card: three steps to migrate to a subdomain](/docs/img/connect-self-domain/apex-migration.webp)

Old links keep working: visitors coming to `example.com` land on the same pages of the subdomain.

If a subdomain is connected with A records, you don't need to change the tunnel or settings. Replace the A records with a single CNAME record from the domain card. The warning disappears after the next DNS recheck, which runs once a day.

![A subdomain card on A records: a suggestion to replace them with a single CNAME record](/docs/img/connect-self-domain/subdomain-a-record.webp)
