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
nano index.html

Then, add some basic HTML boilerplate code, like:

<!DOCTYPE html>
<html lang="en">
    <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>
    <h1>Test Heading</h1>
    <p>Test Text</p>

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

cd ~
cd /etc/nginx/sites-available

Fill in:

server {
    listen 80;
    root /var/www/;
    index index.html index.htm;

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

cd ~
ln -s /etc/nginx/sites-available/ /etc/nginx/sites-enabled/
systemctl restart nginx

Bonus: Expand an existing SSL certificate:

certbot -d --expand

If you navigate to 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.




More posts of this category

Useful Nginx commands for Linux

A collection of useful Nginx commands