Skip to content

Instantly share code, notes, and snippets.

@dev-AshishRanjan
Created March 7, 2025 05:26
Show Gist options
  • Save dev-AshishRanjan/abaede3a5f4f0b736fc2f8fff6906a00 to your computer and use it in GitHub Desktop.
Save dev-AshishRanjan/abaede3a5f4f0b736fc2f8fff6906a00 to your computer and use it in GitHub Desktop.
VPS Setup: git + nginx + certbot + pm2
# Connecting to Your VPS Using SSH - Start with establishing a secure connection to your VPS, ensuring a safe and exclusive access environment for your deployment.
# Updating the VPS - Keep your server up to date with the latest packages and security patches to ensure optimal performance and security.
sudo apt-get update and sudo apt-get upgrade
# Install Node.js:
#For the latest Node.js versions, visit the official Node.js package manager installation guide: https://nodejs.org/en/download/packag...
# Install git:
sudo apt-get install git-all
# Install PM2
npm install pm2@latest -g
# Install NGINX
sudo apt install nginx -y
# Configure NGINX as a reverse proxy for your application. Create and edit a new configuration file:
sudo nano /etc/nginx/sites-available/yourappname.com
server {
listen 80;
server_name yourappname.com;
location / {
proxy_pass http://localhost:3000;
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;
}
}
# Enable the configuration by creating a symlink and then test and reload NGINX:
sudo ln -s /etc/nginx/sites-available/yourappname.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
# Secure Your Application with SSL (HTTPS)
Install Certbot and the NGINX plugin:
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx -d yourappname.com
# Open Necessary Ports in the Firewall
sudo ufw allow ssh
sudo ufw allow http
sudo ufw allow https
sudo ufw enable
sudo ufw status
# Start pm2
pm2 start ecosystem.config.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment