Building Career Without Degree
21 Sep 2024

Setup EC2 with Debian OS
Update and Upgrade Packages
sudo apt updatesudo apt upgradeInstall Node.js
Install PM2 Globally
sudo npm install pm2 -gInstall MongoDB
Allow MongoDB Compass Access
sudo nano /etc/mongod.confSave the MongoDB Configuration
Ctrl + X, Y, EnterRestart MongoDB
sudo systemctl restart mongodCheck MongoDB status:
sudo systemctl status mongodCheck MongoDB Compass Login
mongodb://ec2-ip:27017Install Nginx
sudo apt install nginxChange Ownership for /var/www Directory
sudo chown admin /var/www to allow file permissions.Setup Nginx Reverse Proxy
sudo nano /etc/nginx/sites-available/defaultNginx Configuration Example
server {
listen 80;
server_name _;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Save the Nginx Configuration
Ctrl + X, Y, EnterRestart Nginx
sudo systemctl restart nginxCheck Nginx status:
sudo systemctl status nginxGet SSL on Nginx
Install Certbot and Nginx plugin:
sudo apt install certbot python3-certbot-nginxObtain SSL certificates:
sudo certbot --nginx -d demo.com -d www.demo.comTest SSL certificate renewal:
sudo certbot renew --dry-runHandle SSL Errors (if any)
sudo nano /etc/nginx/sites-available/defaultNginx SSL Configuration Example
server {
listen 80;
server_name demo.com www.demo.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
# Redirect www to non-www
if ($host = 'www.demo.com') {
return 301 http://demo.com$request_uri;
}
# Other necessary configurations
}
Restart Nginx and Check Status
sudo systemctl restart nginxsudo systemctl status nginx