Skip to content

Instantly share code, notes, and snippets.

@ZulianTiger
Last active December 27, 2022 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZulianTiger/383259c672110984cfeb21d266458119 to your computer and use it in GitHub Desktop.
Save ZulianTiger/383259c672110984cfeb21d266458119 to your computer and use it in GitHub Desktop.
How to create additional subdomains on digitalocean ubuntu droplet
1. Configure Nginx as a Reverse Proxy
a) cd /etc/nginx/sites-available (navigate to nginx sites folder)
b) sudo touch api.example.com (create a site enrty)
c) sudo nano api.example.com (open it in a text editor)
d) Add following code in it:
server {
listen 80;
listen [::]:80;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name api.example.com;
location / {
proxy_pass http://localhost:XXXX;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
e) Make sure you replace api.example.com and www.api.example.com with your URLs.
f) sudo ln -s /etc/nginx/sites-available/api.example.com /etc/nginx/sites-enabled/ (create symbolic link)
2. Add subdomains on DNS
a) Go to DNS manager (for example namecheap, godaddy, digitalocean, etc.)
b) If domain is managed by digitalocean click on "Create" dropdown at top right and select "Domain/DNS"
c) Choose your domain and click manage
d) Add an A record to the domain and in the hostname field enter subdomain name (for example api)
e) Select droplet resource and click create
f) You can check if the DNS propagated the new subdomain here: https://www.digitalocean.com/community/tools/dns (It should appear in A records)
3. Run the project
a) Clone project git repo
b) npm install
c) pm2 start --name=website npm -- start
d) pm2 save
e) sudo systemctl restart nginx
4. Obtain SSL Certificates
a) sudo certbot --nginx -d api.example.com
b) sudo certbot renew --dry-run (test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment