Part 1 - Get server instance
Create a Ubuntu server with any provider like AWS, Linode, DigitalOcean, etc.
Add a ssh key.
Part 2 - Get domain name
Get a domain name from any provider like BigRock, Google, etc.
Add an A record with the ipv4 address of the server.
You can add multiple A records with different subdomains with the same ipv4 address.
Add the records in your domain provider DNS only. Don't create new domain in the server provider.
Part 3 - Server connection from local machine
Login via ssh.
Run the following commands,
sudo apt update
sudo apt upgrade -y
Reboot your instance.
Login again via ssh.
Install Node.js via,
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install nodejs
node --version
Create the folder(s) of your server and write the code for it.
Sample server code is,
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
Part 4 - Install pm2
sudo npm i pm2 -g
pm2 start <server-file-name> --name "<process name>"
Part 5 - Setup ufw firewall
sudo ufw enable
sudo ufw status
sudo ufw allow ssh (Port 22)
sudo ufw allow http (Port 80)
sudo ufw allow https (Port 443)
Part 6 - Install NGINX and configure
sudo apt install nginx
sudo nano /etc/nginx/sites-available/default
- Sample server block looks like,
server {
server_name <domain-name>;
location / {
proxy_pass http://localhost:<port of server>;
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;
}
listen 80;
}
- Add this to show default page for all the other URLs,
server {
server_name <IPV4 address of the server>;
root /var/www/html;
index index.nginx-debian.html;
listen 80 default_server;
}
- Check nginx config via,
sudo nginx -t
- Restart nginx via,
sudo service nginx restart
Part 7 - Add SSL with Certbot
- Follow the instructions at Offical website of certbot.
Top comments (0)