{"id":1955,"date":"2015-07-13T15:05:03","date_gmt":"2015-07-13T15:05:03","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=1955"},"modified":"2015-07-31T09:52:40","modified_gmt":"2015-07-31T09:52:40","slug":"how-to-add-a-subdomain-for-nodejs-application-on-digitalocean","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/quick-tips\/how-to-add-a-subdomain-for-nodejs-application-on-digitalocean\/","title":{"rendered":"How to add a subdomain for Nodejs application on DigitalOcean"},"content":{"rendered":"<p>When I was preparing <a href=\"http:\/\/www.nikola-breznjak.com\/blog\/codeproject\/how-to-add-a-comment-field-to-mean-js-article-example\/\">this post<\/a> I bought a domain just for testing purposes called <a href=\"http:\/\/nikola-dev.com\">nikola-dev.com<\/a>\u00a0and I wanted to have Node.js apps running on this VPS (behind a NGINX running as proxy) but that they would be accessible from different domains (for example <a href=\"http:\/\/mean.nikola-dev.com\">mean.nikola-dev.com<\/a>). Below are the steps I needed to take in order to make this happen:<\/p>\n<ol>\n<li>Clearly, have a <a href=\"https:\/\/www.digitalocean.com\/?refcode=974c9bc93d77\">droplet on DigitalOcean<\/a><\/li>\n<li>Buy a domain (where ever you buy it, make sure you use <a href=\"http:\/\/www.joinhoney.com\/\">Honey<\/a>, to get the best price)<\/li>\n<li>Edit the Nameserver information in the admin dashboard of your domain provider (where you bought the domain) to the following three records:<br \/>\nns1.digitalocean.com,\u00a0ns2.digitalocean.com,\u00a0ns3.digitalocean.com<\/li>\n<li>Add the domain on DigitalOcean DNS settings page:<br \/>\n<a href=\"http:\/\/www.nikola-breznjak.com\/blog\/wp-content\/uploads\/2015\/07\/digitalOcean_dns.jpg\" rel=\"lightbox[1955]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1941\" src=\"http:\/\/www.nikola-breznjak.com\/blog\/wp-content\/uploads\/2015\/07\/digitalOcean_dns.jpg\" alt=\"digitalOcean_dns\" width=\"1009\" height=\"415\" srcset=\"https:\/\/nikola-breznjak.com\/blog\/wp-content\/uploads\/2015\/07\/digitalOcean_dns.jpg 1009w, https:\/\/nikola-breznjak.com\/blog\/wp-content\/uploads\/2015\/07\/digitalOcean_dns-300x123.jpg 300w\" sizes=\"auto, (max-width: 1009px) 100vw, 1009px\" \/><\/a><\/li>\n<li>Delete <strong>\/etc\/nginx\/sites-enabled\/default<\/strong><\/li>\n<li>Create\u00a0<strong>\/etc\/nginx\/sites-available\/nikola-dev.com<\/strong>\u00a0file with the following content (this will be a simple single HTML file which will list the available test apps on this server):\n<pre class=\"lang:default decode:true\">server {\r\n    listen 80;\r\n    server_name nikola-dev.com;\r\n    root \/var\/www\/nikola-dev.com\/public_html;\r\n}<\/pre>\n<\/li>\n<li>Create\u00a0<strong>\/etc\/nginx\/sites-available\/mean.nikola-dev.com<\/strong>\u00a0file with the following content (this will serve the actual Node.js app that we&#8217;re building in this tutorial):\n<pre class=\"lang:default decode:true\">server {\r\n    listen 80;\r\n\r\n    server_name mean.nikola-dev.com;\r\n\r\n    location \/ {\r\n        proxy_pass http:\/\/127.0.0.1:3000;\r\n        proxy_http_version 1.1;\r\n        proxy_set_header Upgrade $http_upgrade;\r\n        proxy_set_header Connection 'upgrade';\r\n        proxy_set_header Host $host;\r\n        proxy_cache_bypass $http_upgrade;\r\n    }\r\n}<\/pre>\n<\/li>\n<li>Restart NGINX:\n<pre class=\"lang:default decode:true\">sudo service nginx restart<\/pre>\n<\/li>\n<\/ol>\n<p>Clearly, if you would need to add more subdomains, just repeat the steps from step <strong>6\u00a0<\/strong>onward. Of course, you would need to put your other Node.js apps on <strong>different ports<\/strong>, since only one app can work on one port.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I was preparing this post I bought a domain just for testing purposes called nikola-dev.com\u00a0and I wanted to have Node.js apps running on this VPS (behind a&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1969,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-1955","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-quick-tips"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1955","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=1955"}],"version-history":[{"count":6,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1955\/revisions"}],"predecessor-version":[{"id":1974,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/1955\/revisions\/1974"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/1969"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=1955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=1955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=1955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}