6 min read

How to add a domain name to Directus

It's important to have a domain name for Directus so you're not exposing your IP address and port to the public. You'll need to purchase a domain name from a supplier and set up the DNS record to use your server.

It's important to have a domain name for Directus so you're not exposing your IP address and port to the public. When Directus is installed it does not ask for your domain name nor does it provide a way to create one. This article will cover how you can create a domain name and assign it to Directus.

You'll need to purchase a domain name from a supplier and set up the DNS record to use your server. Then update your proxy web server with the server name and forward traffic to your Directus application.

Let's break this down into some easy steps. First you need a domain name.

Purchase a Domain Name

There are a lot of companies out there that offer domain names. I find the simplest method is to use the same company as your hosting platform and often you'll get the first year free and if lucky the second year too. When you do this at the same time, the DNS records will automatically be created for you.

Here are some hosting providers that can do this. Most offer managed VPS options but if you want to maintain the server yourself, you can go for an unmanaged option which is a bit cheaper.

VPS Hosting Services 🖥️ Managed Virtual Servers at Namecheap
Choose the best cheap managed VPS provider? Namecheap’s VPS Linux-based web solution includes: ✔️ pure SSD ✔️ cPanel ✔️ WHMCS ✔️ 99.99% uptime ✔️ 24/7 Live Chat and more.
Best Managed VPS Hosting Provider | A2 Hosting
With unmatched speed and reliability, our Managed VPS Hosting provides up to 20x the speed of competitors with a 99.9% uptime. Shop now!
Best Web Hosting - Domains - WordPress - Bluehost - 2022
Bluehost is one of the largest website hosting providers and powers millions of websites. Learn more about our secure and reliable hosting services today!
Managed VPS Hosting | 20X Faster SSDs & cPanel | InMotion Hosting
Powerful and secure managed VPS hosting solutions with High-Availability servers, Linux SSDs, cPanel, and WHM - all backed by 24/7 support.
Cloud VPS: Unmanaged VPS Starting at $5/mo | InMotion Hosting
Cloud VPS powered by redundant cloud infrastructure. Each Cloud VPS plan comes with your choice of OS, DDoS protection, and server snapshots.
VPS Hosting | SSD Storage | Get Cheap VPS for $3.95 Only
Get Cloud based VPS hosting to expose your online performance. 30X faster VPS hosting is absolutely stable and secure. Now VPS hosting is up to 77% off!

If you already have a server and you want to purchase an domain name, here are some companies that have good deals:

💡
Got a few domains to purchase? Order them all at once with GoDaddy and you'll get 30% off all of them making the biggest saving.
Cheap Domain Registration - Cheapest Domain Name Registrar: NameSilo
Cheap Domain Registration with NameSilo: Bulk pricing, free private domain name registration & cheapest domain registration prices - No hidden setup fees or mandatory minimums
Buy a domain name - Register cheap domain names from $0.99 - Namecheap
Register domain names at Namecheap. Buy cheap domain names and enjoy 24/7 support. With over 13 million domains under management, you know you’re in good hands.

Make sure to edit your DNS and create a new A record.

Type	Name		IP Address			TTL
A	@		000.000.000.000			1h

Now that you have a domain name and it's pointing to your server, you will need to set up Nginx.

Configure Nginx

If you haven't already installed Nginx, run the following command relative to your OS.

sudo yum install nginx
sudo dnf install nginx
sudo apt-get install nginx

Create a new Nginx config file, where directus.example.com is your new domain name.

vim /etc/nginx/conf.d/directus.example.com.conf

Copy and Paste the following template and replace the server_name and proxy_pass port with your details. You will also need to supply your SSL configuration. If you don't need SSL, remove the listening port 443 line.

server {
    listen 80;
    listen 443 ssl http2;
    server_name directus.example.com;
    
    # Include your SSL details here #

    location / {
        proxy_pass http://127.0.0.1:8055;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        add_header X-Cache $upstream_cache_status;

        proxy_connect_timeout 30s;
        proxy_read_timeout 86400s;
        proxy_send_timeout 30s;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
    
    access_log  /var/log/nginx/directus.example.com.log;
    error_log  /var/log/nginx/directus.example.com.error.log;
}

Save and close your configuration file. If you are unfamilar with vim, make sure to exit the editor mode by pressing ESC, the type :wq and press ENTER.

Test your nginx configuration using:

nginx -t

If unsuccessful, the output will say where the error occured. Address the issue and repeat.

Restart Nginx to apply the changes.

sudo service nginx restart

You can now access Directus from your domain name (assuming the DNS is configured and port 80 and 443 are open on the firewall).

What's next?

It's very important to secure your webiste with an SSL certificate that will encrypt all the data between the client and server. I've written an article about how you can add a certificate to Directus. It's worth a read.

How to add a SSL Certificate to Directus
SSL certificates are vital to securing your data by encrypting all traffic between the client and your server. In this article I’ll cover how you can add a Let’s Encrypt certificate or Paid certificates to Directus. This assumes you are using linux and have root access and have a domain

By continuing to use our website, you consent to use essential cookies. We also use optional tracking cookies which help us gather statistics to improve our services. Do you consent to these cookies?

I Consent Do not track