This guide explains how to deploy your Next.js website as a static site that works with your existing NGINX setup. No running Node.js processes required!
- NGINX configured for
/var/www/bigbraincoding.com/html - PHP support enabled in NGINX (for tracking)
- Node.js and npm installed
# Run the deployment script
./scripts/deploy.shThis script will:
- Install dependencies
- Build the static site
- Create a backup of current site
- Deploy to NGINX directory
- Set proper permissions
- Verify deployment
# 1. Install dependencies
npm install
# 2. Build static site
npm run build
# 3. Copy to NGINX directory
sudo cp -r out/* /var/www/bigbraincoding.com/html/
# 4. Set permissions
sudo chown -R www-data:www-data /var/www/bigbraincoding.com/html/
sudo chmod -R 755 /var/www/bigbraincoding.com/html/output: 'export'- Enables static exportimages: { unoptimized: true }- Required for static exporttrailingSlash: true- Ensures proper routing
Make sure your NGINX config includes:
server {
listen 80;
server_name bigbraincoding.com www.bigbraincoding.com;
root /var/www/bigbraincoding.com/html;
index index.html;
# Handle client-side routing
location / {
try_files $uri $uri/ /index.html;
}
# Handle tracking API
location /api/tracking.php {
try_files $uri =404;
}
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
}- Client-side tracking -
public/tracking.jscollects visitor data - PHP handler -
public/api/tracking.phpreceives and logs data - Local storage - Data saved to
~/bigbraincoding.com/YYYY/MM/DD/
- ✅ Page views and navigation
- ✅ Click events and interactions
- ✅ Form submissions
- ✅ Scroll depth and engagement
- ✅ Device and browser information
- ✅ Session duration and return visits
- ✅ IP addresses and geolocation
- ✅ Performance metrics
# Basic analysis
node scripts/analyze-tracking.js
# Enhanced analysis with performance metrics
node scripts/enhanced-analysis.js# 1. Make your changes to the code
# 2. Test locally: npm run dev
# 3. Deploy: ./scripts/deploy.sh# Find the latest backup
ls -la /tmp/bigbraincoding-backup-*
# Restore from backup
sudo cp -r /tmp/bigbraincoding-backup-YYYYMMDD-HHMMSS/* /var/www/bigbraincoding.com/html/# Clear Next.js cache
rm -rf .next out
npm run build# Fix ownership
sudo chown -R www-data:www-data /var/www/bigbraincoding.com/html/
sudo chmod -R 755 /var/www/bigbraincoding.com/html/- Check browser console for errors
- Verify PHP is enabled in NGINX
- Check file permissions on tracking directory
- Test tracking endpoint:
curl -X POST https://bigbraincoding.com/api/tracking.php
# Test NGINX configuration
sudo nginx -t
# Reload NGINX
sudo systemctl reload nginx
# Check NGINX logs
sudo tail -f /var/log/nginx/error.log- ⚡ Faster loading - No server-side rendering
- 🔒 Better security - No server-side code execution
- 💰 Lower costs - No server resources needed
- 📱 Better caching - Static files cache better
- 🚀 CDN ready - Easy to deploy to CDN
- 📊 Real-time analytics - No external dependencies
- 🔒 Privacy focused - Data stays on your server
- 💾 No data limits - Store as much as you want
- 🎯 Custom insights - Track exactly what you need
- 📧 Email reports - Daily/weekly summaries
- 📊 Real-time dashboard - Live analytics interface
- 🎨 Heat maps - Click and scroll visualization
- 🔄 A/B testing - Track different page versions
- 📱 Mobile app - Analytics on the go
If you encounter issues:
- Check the NGINX error logs
- Verify file permissions
- Test the tracking endpoint manually
- Review the deployment script output
After deployment, you should see:
- ✅ Site loads at
https://bigbraincoding.com - ✅ All pages work without 404s
- ✅ Tracking data appears in
~/bigbraincoding.com/ - ✅ No console errors in browser
- ✅ Fast page load times
Happy deploying! 🚀