If you are hosting an Nginx server on Linode, you can follow these steps to add a new subdomain:
On the Linode website:
- Go to Domains and click on the domain, to which the subdomain should be added
- Click "Add an A/AAAA Record"
- To fill in the fields (in this example, the full url will be "test.yourdomain.com"):
- Hostname: test
- IP Adress: the IP Address of your domain on Linode
- Click "Save"
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.