{"id":9628,"date":"2022-09-07T16:47:11","date_gmt":"2022-09-07T11:17:11","guid":{"rendered":"https:\/\/www.skynats.com\/?p=9628"},"modified":"2023-06-15T17:09:06","modified_gmt":"2023-06-15T11:39:06","slug":"add-subdomain-with-nginx-digitalocean","status":"publish","type":"post","link":"https:\/\/www.skynats.com\/blog\/add-subdomain-with-nginx-digitalocean\/","title":{"rendered":"Add Subdomain With NGINX DigitalOcean"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">With the help of this article, adding a subdomain with NGINX in DigitalOcean became simple. With our <a href=\"https:\/\/www.skynats.com\/digitalocean-management\/\" target=\"_blank\" rel=\"noreferrer noopener\">DigitalOcean Support Services<\/a>, <em><strong>Skynats<\/strong><\/em> can handle your DigitalOcean issues.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-adding-a-subdomain-with-nginx-in-digitalocean\">Adding a subdomain with NGINX in DigitalOcean<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">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&#8217;s NGINXConfig.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We&#8217;ll go over how to add a subdomain with NGINX on DigitalOcean in this article.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Pre-requisites<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>An Ubuntu server on DigitalOcean<\/li><li>NGINX and SSL on DigitalOcean&nbsp;<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Following are the steps:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Make an &#8220;A&#8221; record first for the subdomain.<\/li><li>Then make an index file and subdomain directory.<\/li><li>Make an NGINX server block for the subdomain as well.<\/li><li>For security, add an SSL certificate right away.<\/li><li>&nbsp;Lastly, access the subdomain.<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s go over each step in detail.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1. Make an &#8220;A&#8221; record first for the subdomain:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2. Then make an index file and a subdomain directory:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create the subdomain first, then add the index file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>subdomain_dir=\/var\/www\/apps.example.com\r\n# Create directory\r\nsudo mkdir $subdomain_dir\r\n# Create index.html\r\nsudo touch $subdomain_dir\/index.html<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The contents of the index file can be modified. The content appears as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\r\n&lt;html>\r\n&lt;head>\r\n&lt;title>Welcome to Example Appstore!&lt;\/title>\r\n&lt;style>\r\n    body {\r\n        width: 35em;\r\n        margin: 0 auto;\r\n        font-family: Tahoma, Verdana, Arial, sans-serif;\r\n    }\r\n&lt;\/style>\r\n&lt;\/head>\r\n&lt;body>\r\n&lt;h1>Welcome to Example Appstore!&lt;\/h1>\r\n&lt;p>This site is under active development.&lt;\/p>\r\n\r\n&lt;h2>Related Websites&lt;\/h2>\r\n&lt;a href = \"https:\/\/www.datanovia.com\">Datanovia&lt;\/a>&lt;br\/>\r\n&lt;\/body>\r\n&lt;\/html><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>3. Make an NGINX server block for the subdomain as well:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The subdomain is now enabled on the NGINX server.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># 1. Copy the default subdomain configuration\r\nmysubdomain=\"apps.example.com\"\r\nsudo cp \/etc\/nginx\/sites-available\/default \/etc\/nginx\/sites-available\/$mysubdomain\r\nsudo ln -s \/etc\/nginx\/sites-available\/$mysubdomain \/etc\/nginx\/sites-enabled\/$mysubdomain\r\n  \r\n# 2. Open the config file\r\nsudo nano \/etc\/nginx\/sites-available\/$mysubdomain\r\n  \r\n# 3. Edit the file\r\n# The content will look like this\r\nserver {\r\n        listen 80;\r\n        listen &#91;::]:80;\r\n        root \/var\/www\/apps;\r\n        index index.html;\r\n        server_name apps.example.com;\r\n}\r\n  \r\n# 4. Restart NGINX\r\nsudo service nginx restart<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>4. For security, add an SSL certificate right away:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Obtain an SSL Certificate\r\nsudo certbot --nginx -d $mysubdomain<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>5. Lastly, access the subdomain:<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Go to the subdomain at this point.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Conclusion<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we offer a straightforward technique developed by our tech team for adding a subdomain with NGINX in DigitalOcean.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Are you looking for an answer to another query?\u00a0<a href=\"https:\/\/www.skynats.com\/contact-us\/\" target=\"_blank\" rel=\"noreferrer noopener\"><em>Contact<\/em><\/a>\u00a0our technical support team.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-9628","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/9628","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/comments?post=9628"}],"version-history":[{"count":0,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/posts\/9628\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/media?parent=9628"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/categories?post=9628"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skynats.com\/blog\/wp-json\/wp\/v2\/tags?post=9628"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}