- Arvancloud (بهترین برای CDN): arvancloud.ir
- Pardaz: pardaz.ir
- Rayanserver: rayanserver.ir
- Hostiran: hostiran.net
- Tarafdari: tarafdari.com
- .ir domains: irannic.ir (ثبت دامنههای ایرانی)
- International: Namecheap, GoDaddy (faster setup)
- Recommended: Buy .ir domain for local credibility
cd client
npm install
npm run build
# Creates dist/ folder with optimized static files# server/.env (Production)
PORT=3000
NODE_ENV=production
# MongoDB - Choose one:
# Option A: Local MongoDB on server
MONGO_URI=mongodb://127.0.0.1:27017/bodybuilding
# Option B: Hosted MongoDB Atlas (recommended)
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/bodybuilding?retryWrites=true&w=majority
# Generate new random secret:
# node -e "console.log(require('crypto').randomBytes(48).toString('hex'))"
JWT_SECRET=<your-new-random-secret-here>
JWT_EXPIRES_IN=7d
# Update to your domain
CLIENT_ORIGIN=https://yourdomain.irssh user@your-server-ip# Update system
sudo apt update && sudo apt upgrade -y
# Install Node.js (v18+)
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
# Install MongoDB (if local)
sudo apt install -y mongodb
# Install PM2 (process manager)
sudo npm install -g pm2
# Install Nginx (reverse proxy)
sudo apt install -y nginxcd /opt
sudo git clone https://github.com/yourusername/bodybuilding.git
cd bodybuilding
sudo chown -R $USER:$USER .
npm installnpm run buildCreate /etc/nginx/sites-available/bodybuilding:
upstream backend {
server 127.0.0.1:3000;
}
server {
listen 80;
listen [::]:80;
server_name yourdomain.ir www.yourdomain.ir;
# Redirect to HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name yourdomain.ir www.yourdomain.ir;
# SSL Certificates (use Certbot with Let's Encrypt)
ssl_certificate /etc/letsencrypt/live/yourdomain.ir/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.ir/privkey.pem;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
# Gzip compression
gzip on;
gzip_types text/plain text/css application/json application/javascript;
gzip_min_length 1000;
# API requests -> Node.js server
location /api/ {
proxy_pass http://backend;
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;
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;
}
# Static files (client build)
location / {
root /opt/bodybuilding/client/dist;
try_files $uri $uri/ /index.html;
}
# Cache static assets
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}Enable site:
sudo ln -s /etc/nginx/sites-available/bodybuilding /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginxsudo apt install -y certbot python3-certbot-nginx
sudo certbot certbot -d yourdomain.ir -d www.yourdomain.irThis will auto-configure Nginx! Then:
sudo systemctl restart nginxsudo systemctl start mongodb
sudo systemctl enable mongodb- Go to mongodb.com/cloud/atlas
- Create free cluster
- Get connection string
- Use in
.envasMONGO_URI
cd /opt/bodybuilding
# Start server with PM2
pm2 start server/server.js --name bodybuilding
# Make PM2 start on reboot
pm2 startup
pm2 save
# Monitor
pm2 monit
pm2 logs bodybuildingCreate deployment script deploy.sh:
#!/bin/bash
cd /opt/bodybuilding
git pull origin main
npm install
npm run build
pm2 restart bodybuilding
sudo systemctl restart nginx
echo "✅ Deployed successfully"Make executable:
chmod +x deploy.shRun to deploy:
./deploy.sh-
Register domain on irannic.ir or international registrar
-
Point DNS to your server IP:
- Type: A
- Host: @
- Value: your-server-ip
- TTL: 3600
-
Add DNS records:
A @ your-server-ip A www your-server-ip -
Wait 24-48 hours for DNS propagation
Before going live, verify:
# SSH into server and check
ssh user@your-server-ip
cat /opt/bodybuilding/server/.env
# Should have:
✅ PORT=3000
✅ NODE_ENV=production
✅ MONGO_URI=<valid connection>
✅ JWT_SECRET=<long random string>
✅ CLIENT_ORIGIN=https://yourdomain.irpm2 logs bodybuilding
sudo tail -f /var/log/nginx/access.loghtop
df -hmongodump --db bodybuilding --out /backups/bodybuilding-$(date +%Y%m%d)sudo crontab -e
# Add: 0 2 * * * mongodump --db bodybuilding --out /backups/bodybuilding-$(date +\%Y\%m\%d)# Check Nginx
sudo nginx -t
sudo systemctl restart nginx
# Check Node.js process
pm2 status
pm2 logs bodybuilding
# Check firewall
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 22/tcpUpdate server/.env:
CLIENT_ORIGIN=https://yourdomain.ir
Then restart: pm2 restart bodybuilding
# Restart server
pm2 restart bodybuilding
# Check logs
pm2 logs bodybuilding --lines 100
# Check MongoDB
mongo
> db.stats()- Hosting: 50,000 - 200,000 ریال
- Domain (.ir): 100,000 - 150,000 ریال/سال
- MongoDB Atlas: Free (or $10+ for larger data)
- SSL: Free (Let's Encrypt)
- Server rented and SSH access working
- Node.js v18+ installed
- Nginx installed and configured
- MongoDB running (local or Atlas)
- Domain registered and DNS pointing to server
- SSL certificate installed
-
.envconfigured with production values -
npm run buildproduces client/dist - PM2 managing Node.js process
-
yourdomain.irloads without CORS errors
Questions? DM icwt.life@gmail.com