Multi level domain with CNAMEMulti level domain with CNAME

Its looks cool to have multi-level subdomains for different projects. example: https://api.cms.adapttive.com/ or https://api.store.adapttive.com/

DNS configuration

  • Goto DNS panel of your domain and create a CNAME record for you multi-level sub-domain which points to your real server.
  • For example:

    CNAME api.cms.adapttive.com api.adapttive.com

    A api.adapttive.com 8.8.8.8

  • Here, my single server serves two different APIs
  • Note: CNAME can be pointed to another domain only. So, api.adapttive.com is A record points my actual server (ex: 8.8.8.8).
  • Google offers a great tool to verify your DNS configurations. You should check out Dig Tool.

Nginx configuration

  • You can add a api.cms.adapttive.com.conf config to serve the request, for example:
// api.cms.adapttive.com.conf
upstream strapi {
    server 127.0.0.1:1337;
}
server {
    listen 80;
    listen [::]:80;
    server_name api.cms.adapttive.com;

    location / {
         proxy_pass http://strapi;
         proxy_http_version 1.1;
         proxy_set_header X-Forwarded-Host $host;
         proxy_set_header X-Forwarded-Server $host;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
         proxy_set_header X-Forwarded-Proto $scheme;
         proxy_set_header Host $http_host;
         proxy_set_header Upgrade $http_upgrade;
         proxy_set_header Connection "Upgrade";
         proxy_pass_request_headers on;
    }
}