How to configure a subdomain using CNAME via GoCache API
To use GoCache you must fetch your API token.
To find your API token, log in to the GoCache dashboard and click on "Minha Conta" (My Account) in the top bar.
Activate the "Conta" (Account) tab and click on the "Visualizar token" (View token) button.
Your API token will be displayed.
1. Register your domain
To register a domain via API, make a POST request to the /v1/domain/{domain_name}
endpoint:
Important: You must register the domain name with this endpoint, not a subdomain (e.g. gocache.com.br, not www.gocache.com.br), even if you're planning on activating GoCache in a subdomain.
e.g.
$ curl -i https://api.gocache.com.br/v1/domain/mydomain.com \
-X POST \
-H 'GoCache-Token: YOUR_API_TOKEN' \
-d 'cache_ttl=86400' \
-d 'gzip_status=true'
All parameters are available in the API documentation page.
2. Register DNS subdomains
To register subdomains for your domain, make a POST request to the /v1/dns/{domain_name}
endpoint.
Example to register an A entry for www.mydomain.com pointing to the 1.2.3.4 ip address, with a ttl of 10 minutes (600s):
$ curl -i https://api.gocache.com.br/v1/dns/mydomain.com \
-X POST \
-H 'GoCache-Token: YOUR_API_TOKEN' \
-d 'name=www' \
-d 'type=A' \
-d 'content=1.2.3.4' \
-d 'ttl=600' \
-d 'cloud=1'
On success, the entry is returned in a JSON format, identified by the record_id
number:
HTTP/1.1 200 OK
{
"status_code": 1,
"response": {
"records" : [
{
"name" : "www"
"content" : "192.168.256.99",
"type" : "A",
"ttl" : "600"
"cloud" : "1",
"record_id" : "99995",
}
]
}
}
All parameters are available in the API documentation page.
3. Optional, insert a custom SSL certificate
GoCache will create an automatic SSL certificate after your subdomains DNS entries are pointed to GoCache. It may take several minutes to generate this certificate and your subdomains will display an "Incorrect certificate" error message in the meantime.
To prevent this error, you may upload your own SSL certificate (only a single custom certificate is allowed per domain).
To insert a custom certificate, make a POST request to the /v1/ssl/certificate/{domain_name}
endpoint.
The certificate
parameter value must be a PEM encoded certificate. The privatekey
parameter value must be a PEM encoded private key.
Important: Encrypted certificates or private keys are not allowed. You must decrypt it before installing in GoCache.
$ curl -i https://api.gocache.com.br/v1/ssl/certificate/mydomain.com \
-X POST \
-H 'Content-Type: application/json' \
-H 'GoCache-Token: YOUR_API_TOKEN' \
--data-binary \
'{
"certificate": "
-----BEGIN CERTIFICATE-----
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
-----END CERTIFICATE-----
",
"privatekey": "
-----BEGIN PRIVATE KEY-----
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
-----END PRIVATE KEY-----
",
"enable": true
}'
All parameters are available in the API documentation page.
4. Point subdomains to GoCache in your DNS server
Each DNS entry registered in step 2 will generate a CNAME in the format {subdomain.domain}.cdn.gocache.net
. To activate GoCache, your subdomain entries must be pointed to this value in your DNS server.
Example:
www.mydomain.comn => www.mydomain.com.cdn.gocache.net
blog.mydomain.com => blog.mydomain.com.cdn.gocache.net
To point the www
subdomain to GoCache in your DNS server, modify the DNS entry www
to the type CNAME
with value www.mydomain.com.cdn.gocache.net
.
www IN CNAME www.mydomain.com.cdn.gocache.net.
To point the blog
subdomain to GoCache in your DNS server, modify the DNS entry blog
to the type CNAME
with value blog.mydomain.com.cdn.gocache.net
.
blog IN CNAME blog.mydomain.com.cdn.gocache.net.
After the DNS propagation interval configured in your DNS server expires, your subdomains will be available in GoCache for HTTP and HTTPS traffic.