The Be Sure Blog

Code Snippets | Problem Solving | Tips & Tricks

The Be Sure Blog banner

Add a subdomain to Nginx and Linode

posted on 11.1.2023 by Below Surface in "Nginx"

If you are hosting an Nginx server on Linode, you can follow these steps to add a new subdomain:

On the Linode website:


Nginx (if any of the commands does not work, try to add "sudo" in front). SSH into your Linode server and run these commands:

cd /var/www
mkdir test.yourdomain.com
cd test.yourdomain.com
nano index.html

Then, add some basic HTML boilerplate code, like:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test Title</title>
</head>
<body>
    <h1>Test Heading</h1>
    <p>Test Text</p>
</body>
</html>

Save and exit the editor with ctrl + o, ctrl + enter + ctrl x

cd ~
cd /etc/nginx/sites-available
nano test.yourdomain.com

Fill in:

server {
    listen 80;
    server_name test.yourdomain.com www.test.yourdomain.com;
    root /var/www/test.yourdomain.com;
    index index.html index.htm;
}

Save and exit the editor with ctrl + o, ctrl + enter + ctrl x

cd ~
ln -s /etc/nginx/sites-available/test.yourdomain.com /etc/nginx/sites-enabled/test.yourdomain.com
systemctl restart nginx


Bonus: Expand an existing SSL certificate:

certbot -d test.yourdomain.com --expand


If you navigate to test.yourdomain.com now, it should output:

Test Heading
Test Text

And if you succeeded to create a SSL certificate, the website should automatically be using SSL now.

Tags:

nginx
subdomain

Sources:

https://www.linode.com/docs/products/networking/dns-manager/guides/common-dns-configurations/

More posts of this category

Useful Nginx commands for Linux

A collection of useful Nginx commands

Nginx