tutorials2 Min Read

How To Create Admin Subdomain In Cloudflare with Nginx Proxy using Docker with SSL

Gorav Singal

August 30, 2022

TL;DR

Create a subdomain in Cloudflare DNS, configure Nginx as a reverse proxy in Docker to route the subdomain to your admin panel (e.g., Strapi on port 8080), and secure it with SSL.

How To Create Admin Subdomain In Cloudflare with Nginx Proxy using Docker with SSL

Introduction

I have my main website, which I run on Lets say: gyanbyte.com. Now, there is my admin panel, or admin-ui which is a separate deployable artifact altogether. My admin panel runs on port 8080. It can be any CMS like Strapi, which runs on 8080.

Website runs with Cloudflare.

One way to open admin panel is IP:8080. But, I want to use SSL and a proper domain name. Another way could be to write a proxy which redirects /admin to that admin panel. But, there is no such path that can differentiate my main website UI and this admin panel.

Create Subdomain in Cloudflare

Login to cloudflare, open DNS settings for your website. I assume, you have two records already:

  • A-record with name as your website name, value as your hosting IP
  • CNAME-record with name as www and value as yourwebsite.com

Now, we need to add another CNAME record. With name as admin and value as yourwebsite.com So, I want my website to open as admin.yourwebsite.com

Save it. Now, it is the turn to configure your nginx proxy.

Generate SSL Cert for admin Subdomain

Before moving to Nginx, you also need to create SSL certificate. I used Lets-Encrypt. Now, I have my cert for three names:

Configure Nginx Proxy

Configuration file:

upstream my_ui {
    least_conn;

    server my_ui:3000 max_fails=3 fail_timeout=60 weight=1;
}
upstream my_api {
    ip_hash;
    least_conn;

    server my_api:8080 max_fails=3 fail_timeout=60 weight=1;
}
upstream my_admin {
    ip_hash;
    least_conn;

    server my_api:8080 max_fails=3 fail_timeout=60 weight=1;
}

server {
    listen 80;
    server_name yourwebsite.com www.yourwebsite.com;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }
    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    server_name yourwebsite.com www.yourwebsite.com;

    keepalive_timeout   70;
    client_max_body_size 50M;

    ssl_certificate /etc/letsencrypt/live/yourwebsite.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourwebsite.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location /  {
        add_header Pragma "no-cache";
        add_header Cache-Control "no-cache, must-revalidate";
        gzip_static on;

        proxy_pass http://my_ui/;
    }

    location /api/ {
        rewrite ^/api/?(.*)$ /$1 break;
        proxy_pass http://my_api;
        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;
    }
}

server {
    listen 443 ssl;
    server_name admin.yourwebsite.com;

    keepalive_timeout   70;
    client_max_body_size 50M;

    ssl_certificate /etc/letsencrypt/live/yourwebsite.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourwebsite.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    location /  {
        add_header Pragma "no-cache";
        add_header Cache-Control "no-cache, must-revalidate";
        gzip_static on;

        proxy_pass http://my_admin/;
    }
}

Restart or reload your Nginx server. I use docker, just restart your containers.

And, it will just open well, with your admin.yourwebsite.com

Hope it helps.

Share

Related Posts

How to Deploy Strapi with Next.js Frontend with Nginx Proxy and URL Redirect with Docker

How to Deploy Strapi with Next.js Frontend with Nginx Proxy and URL Redirect with Docker

Agenda I will cover following in this post: Prepare Docker image for Next.js app…

How to Copy Local Docker Image to Another Host Without Repository and Load

How to Copy Local Docker Image to Another Host Without Repository and Load

Introduction Consider a scenario where you are building a docker image on your…

How to configure Grafana (Free version) with oAuth Okta, with SSL on Kubernetes

How to configure Grafana (Free version) with oAuth Okta, with SSL on Kubernetes

Introduction In our previous post How to configure Grafana on docker, we saw how…

How to connect to a running mysql service on host from a docker container on same host

How to connect to a running mysql service on host from a docker container on same host

Introduction I have a host running mysql (not on a container). I have to run an…

How to configure Grafana (Free version) with oAuth Okta, with SSL on Docker,Nginx and Load dashboard from json

How to configure Grafana (Free version) with oAuth Okta, with SSL on Docker,Nginx and Load dashboard from json

Introduction In this post, we will see: use Grafana Community Edition (Free…

React JS router not working on Nginx docker container

React JS router not working on Nginx docker container

Problem Statement I developed a simple ReactJS application where I have used…

Latest Posts

AI Video Generation in 2025 — Models, Costs, and How to Build a Cost-Effective Pipeline

AI Video Generation in 2025 — Models, Costs, and How to Build a Cost-Effective Pipeline

AI video generation went from “cool demo” to “usable in production” in 2024-202…

AI Models in 2025 — Cost, Capabilities, and Which One to Use

AI Models in 2025 — Cost, Capabilities, and Which One to Use

Choosing the right AI model is one of the most impactful decisions you’ll make…

AI Image Generation in 2025 — Models, Costs, and How to Optimize Spend

AI Image Generation in 2025 — Models, Costs, and How to Optimize Spend

Generating one image with AI costs between $0.002 and $0.12. That might sound…

AI Coding Assistants in 2025 — Every Tool Compared, and Which One to Actually Use

AI Coding Assistants in 2025 — Every Tool Compared, and Which One to Actually Use

Two years ago, AI coding meant one thing: GitHub Copilot autocompleting your…

AI Agents Demystified — It's Just Automation With a Better Brain

AI Agents Demystified — It's Just Automation With a Better Brain

Let’s cut through the noise. If you read Twitter or LinkedIn, you’d think “AI…

Supply Chain Security — Protecting Your Software Pipeline

Supply Chain Security — Protecting Your Software Pipeline

In 2024, a single malicious contributor nearly compromised every Linux system on…