With the help of this article, adding a subdomain with NGINX in DigitalOcean became simple. With our DigitalOcean Support Services, Skynats can handle your DigitalOcean issues.
Adding a subdomain with NGINX in DigitalOcean
Nginx is one of the most widely used web servers in the world, hosting some of the busiest and greatest websites on the internet. It is a straightforward choice that can act as a reverse proxy, mail server, or web server. The most user-friendly method of configuring a fast, safe, and reliable NGINX server is through DigitalOcean’s NGINXConfig.
We’ll go over how to add a subdomain with NGINX on DigitalOcean in this article.
Pre-requisites
- An Ubuntu server on DigitalOcean
- NGINX and SSL on DigitalOcean
Following are the steps:
- Make an “A” record first for the subdomain.
- Then make an index file and subdomain directory.
- Make an NGINX server block for the subdomain as well.
- For security, add an SSL certificate right away.
- Lastly, access the subdomain.
Let’s go over each step in detail.
1. Make an “A” record first for the subdomain:
Go to the DNS settings page to access the records that contain the primary domain DNS settings. Afterward, by including only the subdomain portion in the Enter Name field, add an A record with a subdomain.
2. Then make an index file and a subdomain directory:
Create the subdomain first, then add the index file.
subdomain_dir=/var/www/apps.example.com
# Create directory
sudo mkdir $subdomain_dir
# Create index.html
sudo touch $subdomain_dir/index.html
The contents of the index file can be modified. The content appears as follows:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to Example Appstore!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to Example Appstore!</h1>
<p>This site is under active development.</p>
<h2>Related Websites</h2>
<a href = "https://www.datanovia.com">Datanovia</a><br/>
</body>
</html>
3. Make an NGINX server block for the subdomain as well:
The subdomain is now enabled on the NGINX server.
# 1. Copy the default subdomain configuration
mysubdomain="apps.example.com"
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/$mysubdomain
sudo ln -s /etc/nginx/sites-available/$mysubdomain /etc/nginx/sites-enabled/$mysubdomain
# 2. Open the config file
sudo nano /etc/nginx/sites-available/$mysubdomain
# 3. Edit the file
# The content will look like this
server {
listen 80;
listen [::]:80;
root /var/www/apps;
index index.html;
server_name apps.example.com;
}
# 4. Restart NGINX
sudo service nginx restart
4. For security, add an SSL certificate right away:
# Obtain an SSL Certificate
sudo certbot --nginx -d $mysubdomain
5. Lastly, access the subdomain:
Go to the subdomain at this point.
Conclusion
In this article, we offer a straightforward technique developed by our tech team for adding a subdomain with NGINX in DigitalOcean.
Are you looking for an answer to another query? Contact our technical support team.