your-domain.com, /var/www/your-app/) with your actual domains and paths during setup.
Overview
The system uses a split-domain layout in production:
https://app.your-domain.com— React dashboard (static files)https://api.your-domain.com— Node.js API + Socket.io (Apache reverse proxy)
Architecture
Request flow:- Browser loads the React SPA from Apache (
DocumentRoot). - API calls go to
https://api.your-domain.com/api/...— Apache proxies to Node on127.0.0.1:5000. - Socket.io connects to
https://api.your-domain.com— Apache upgrades WebSocket traffic to the same Node process. - PM2 keeps the backend running; MongoDB and Zerodha Kite are external dependencies.
Server directory layout
Confirm actual paths on your EC2 instance during first deploy. Example layout:/var/www/NiftyBankNifty/server for the backend. Adjust paths to match your server.
One-time EC2 setup
Run on a fresh Ubuntu EC2 instance (via MobaXterm SSH).System packages
nvm if your version requirements differ):
Apache modules
Enable modules required for reverse proxy and WebSocket support:Timezone
Trading cron jobs use IST. Set server timezone:AWS Security Group
Allow inbound traffic:
Restrict SSH (port 22) to trusted IPs where possible.
MongoDB
SetMONGO_URI in the backend .env pointing to:
- MongoDB Atlas (recommended for production), or
- A self-hosted MongoDB instance (same EC2 or separate)
SSL (optional but recommended)
Use Let’s Encrypt Certbot after Apache vhosts are configured:MobaXterm access
SSH session
- Open MobaXterm → Session → SSH.
- Remote host: EC2 public IP or DNS name.
- Username:
ubuntu(default for Ubuntu AMIs). - Advanced SSH settings → use your AWS
.pemkey file. - Connect.
SFTP (file transfer)
In the same SSH session, MobaXterm opens an SFTP browser panel automatically. Typical uses:
Recommended workflow:
- Use
git pullon the server for code updates (backend and optionally frontend source). - Use SFTP for
.envsecrets, one-off file uploads, or emergency hotfixes. - Never commit
.envfiles to git.
Backend deployment (PM2)
See PM2 deployment for first-time setup, routine deploy, and verification commands. Environment variables are loaded viasrc/env.ts (dotenv.config()). The .env file must live in the server working directory.
Frontend deployment (Apache static)
See Apache configuration for Vite build env, static deploy, and virtual host files. Vite bakes environment variables at build time. Set production values in.env before running yarn build.
Environment variables checklist
Backend — server/.env
Never commit this file. Create on server via MobaXterm SFTP or nano.
Optional market hour overrides:
MCX_START_HOUR, NFO_START_HOUR, CDS_*, etc.
Full Zerodha auto-login setup: see Zerodha auto-login.
Frontend — build-time .env
Post-deploy verification
Zerodha-specific checks
After deploy or server restart, see Zerodha troubleshooting for log patterns:Troubleshooting
For Zerodha token refresh and streaming issues, see Zerodha auto-login and Zerodha troubleshooting.
Related documentation
Summary
- Deploy on AWS EC2 Ubuntu with Apache (static React + reverse proxy) and PM2 (Node backend).
- Use MobaXterm for SSH commands and SFTP file transfer (especially
.envsecrets). - Typical layout:
app.your-domain.comfor UI,api.your-domain.comfor API + Socket.io. - Backend:
git pull→npm install→npm run build→pm2 restart nifty-backend. - Frontend: set Vite env vars →
yarn build→ copybuild/to Apache docroot. - PM2 cwd must be the server folder so
.envloads correctly. - Rebuild frontend whenever API or Socket URLs change — Vite env is compile-time.
- Confirm paths, domains, and SSL on your EC2 instance during first deploy.