|
| 1 | +# How to setup a custom domain |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +Skygear provides default suffixed domain `.skygearapp.com` for you to access your application. You can update your application to use a custom domain which owned by you instead of the skygear generated domain. |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +To setup custom domain, you need to install and configure `skycli` properly. Please follow [this guide](../set-up/set-up-steps.md) to setup skycli. |
| 10 | + |
| 11 | +## Setup custom domain |
| 12 | + |
| 13 | +### 1. Add custom domain |
| 14 | + |
| 15 | +```bash |
| 16 | +$ skycli domain add <your_domain> |
| 17 | + |
| 18 | +#example |
| 19 | +$ skycli domain add www.example.com --app=myapp |
| 20 | +``` |
| 21 | + |
| 22 | +### 2. Verify domain ownership |
| 23 | + |
| 24 | +#### Add DNS records in your DNS provider |
| 25 | + |
| 26 | +After adding the custom domain, please follow the instructions shown in the console and add dns records in your dns provider. |
| 27 | + |
| 28 | +```bash |
| 29 | +#exmaple |
| 30 | +$ skycli domain add www.example.com --app=myapp |
| 31 | +Added domain www.example.com successfully! |
| 32 | + |
| 33 | +Add following DNS records in your DNS provider. |
| 34 | + |
| 35 | +TYPE HOST VALUE |
| 36 | +TXT _skygear.example.com <txt_record_value> |
| 37 | +A www.example.com <a_record_value> |
| 38 | + |
| 39 | +After updating DNS records, run `skycli domain verify www.example.com` to verify domain. |
| 40 | +``` |
| 41 | + |
| 42 | +#### Ask Skygear Cluster to verify the domain |
| 43 | + |
| 44 | +```bash |
| 45 | +$ skycli domain verify <your_domain> |
| 46 | + |
| 47 | +#example |
| 48 | +$ skycli domain verify www.example.com --app=myapp |
| 49 | +Success! You can now access your app through www.example.com. |
| 50 | +Your site may show a security certificate warning until the certificate has been provisioned. |
| 51 | +``` |
| 52 | +
|
| 53 | +After verifying the domain successfully, you can now access your application with the new domain. |
| 54 | +
|
| 55 | +### 3. \(Optional\) Setup custom certificate |
| 56 | +
|
| 57 | +Skygear Cluster by default provisions SSL certificate signed by [Let's Encrypt](https://letsencrypt.org/). If you want to use your own certificate, you can update it with `skycli domain update` command. |
| 58 | +
|
| 59 | +```bash |
| 60 | +# Create tls secret |
| 61 | +$ skycli secret create <your_tls_secret_name> --type=tls --cert=<path/to/tls-cert.pem> --key=<path/to/tls-key.pem> |
| 62 | +# Update domain to use tls secret |
| 63 | +$ skycli domain update <your_domain> --tls-secret=<your_tls_secret_name> |
| 64 | +
|
| 65 | +
|
| 66 | +#example |
| 67 | +$ skycli secret create myapp-tls --type=tls --cert=path/to/tls-cert.pem --key=path/to/tls-key.pem --app=myapp |
| 68 | +Success! Created secret myapp-tls |
| 69 | +
|
| 70 | +$ skycli domain update example.com --tls-secret=myapp-tls --app=myapp |
| 71 | +Success! Updated domain example.com |
| 72 | +
|
| 73 | +$ skycli domain list --app=myapp |
| 74 | +DOMAIN VERIFIED CUSTOM_CERT REDIRECT SSL_CERT_EXPIRY CREATED_AT |
| 75 | +example.com true true - 2020-11-26 20:00:00 +08:00 2020-01-01 18:00:00 +08:00 |
| 76 | +``` |
| 77 | +
|
| 78 | +### 4. \(Optional\) Setup redirect |
| 79 | +
|
| 80 | +For some case, you may want to redirect all requests of a custom domain to another specific domain \(e.g. Redirect `example.com` to `www.example.com`\). |
| 81 | +
|
| 82 | +```bash |
| 83 | +$ skycli domain update example.com --redirect-domain=www.example.com |
| 84 | +Success! Updated domain example.com |
| 85 | +
|
| 86 | +$ skycli domain list --app=myapp |
| 87 | +DOMAIN VERIFIED CUSTOM_CERT REDIRECT SSL_CERT_EXPIRY CREATED_AT |
| 88 | +www.example.com true false - - 2019-11-26 18:00:00 +08:00 |
| 89 | +example.com true false www.example.com - 2019-11-26 18:00:00 +08:00 |
| 90 | +``` |
| 91 | +
|
| 92 | +
|
| 93 | +
|
0 commit comments