ssh root@your_ip_addressThen enter your password.
sudo apt update
sudo apt upgradesudo ufw enable
sudo ufw allow 22Check allow port status:
sudo ufw statuscurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.bashrcVerify installation and install Node.js:
nvm -v
nvm install --lts
# nvm install 18.17.1 (for a specific version)
node -v
npm -vNote: If the version is not showing, please close the terminal and try again, or run source ~/.bashrc.
ls -al ~/.ssh
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
eval "$(ssh-agent -s)"
cat ~/.ssh/id_rsa.pubThen copy the SSH key and paste it into your SSH and GPG keys on GitHub. Click "New SSH key", write the project name, and paste the key.
ssh -T git@github.comsudo ufw allow 80/tcp
sudo ufw allow 3000
sudo ufw allow 443/tcp
sudo ufw reload
sudo apt install nginx -y
sudo systemctl status nginx
sudo systemctl start nginx
sudo systemctl enable nginx
sudo ufw allow 'Nginx Full'
sudo ufw enableMongoDB Installation Import the public key and create the list file for MongoDB 7.0 (Ubuntu 22.04):
sudo apt-get install gnupg curl -y
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
--dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.listUpdate and install:
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo systemctl start mongod
sudo systemctl enable mongodUpdate and install MySQL Server:
sudo apt update
sudo apt install mysql-server -y
sudo systemctl start mysql
sudo systemctl enable mysqlSecure the MySQL installation:
sudo mysql_secure_installationYou can configure Nginx using one of two methods. Both methods support Next.js, Backend, and WebSockets.
Create the configuration file:
sudo nano /etc/nginx/sites-available/yourdomain.comCreate a .conf file directly:
sudo nano /etc/nginx/conf.d/yourdomain.confWhichever option you chose above, add the following server blocks to the file as needed:
# 1. Next.js Frontend
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://localhost:3000; # Next.js runs on port 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;
}
}
# 2. Backend Server
server {
listen 80;
server_name api.myfinancialtrading.com; # Replace with your domain
location / {
proxy_pass http://localhost:3000; # Update port if different
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
# 3. WebSocket (Optional)
server {
listen 80;
server_name ws.myfinancialtrading.com; # Replace with your domain
client_max_body_size 1000M;
location / {
proxy_pass http://localhost:5008;
# WebSocket-specific headers
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
# Additional proxy headers
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Disable caching for WebSocket connections
proxy_cache_bypass $http_upgrade;
}
}If you used Option 1, you must enable the site by creating a symlink:
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/(If you used Option 2, skip the symlink step.)
For both options, test and reload Nginx:
sudo nginx -t
sudo systemctl reload nginxgit clone <git repository using ssh>
cd <project-folder>
npm install
npm run build
npm run startInstall and configure PM2:
npm install -g pm2
pm2 --version
pm2 start npm --name "project-frontend" -- start # For Next.js frontend
pm2 start dist/server.js --name "bigmama-backend" # For backend
pm2 list
pm2 startup
pm2 saveUseful PM2 commands:
pm2 restart all # Restart all apps
pm2 stop nextjs-app # Stop a specific app
pm2 delete nextjs-app # Delete a specific appsudo ufw allow 27017
sudo nano /etc/mongod.conf Add/modify the replication section:
replication:
replSetName: "rs0"Restart MongoDB and initialize the replica set:
sudo systemctl restart mongod
mongoshInside the MongoDB shell:
rs.initiate()For your .env file, use the following connection string:
DATABASE_URL="mongodb://127.0.0.1:27017/kumba?replicaSet=rs0"sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com