Production-Ready Server Setup

Complete walkthrough: secure remote server - Nginx - Domain & SSL - React + Django deployment

DevOps Handbook - Best practices

1. Remote Server Setup & Hardening

Target: any Ubuntu 22.04 / 24.04 LTS VPS (DigitalOcean, AWS EC2, Linode, Hetzner).

Initial Server Provisioning

Security Hardening (Critical)

Tip: After disabling password auth, always keep your SSH private key safe. Use SSH agent for convenience.

2. Installing & Configuring Nginx

Nginx will act as a reverse proxy for both React (static) and Django (dynamic) applications.

Later we will update this config to proxy to React (port 3000 or static build) and Django (via Gunicorn on socket/port 8000). Don't worry, SSL will be added after domain resolves.

3. Domain Registration & SSL (Let's Encrypt)

Obtain a Domain Name

Secure with SSL (Let's Encrypt - free & automated)

Bonus: Setup automatic renewal via cron (Certbot already adds timer). SSL certs valid for 90 days, auto-renewed.

4. Deploy React Application

Two approaches: build static files locally & upload, or build on server. We'll show best practice using CI/CD or manual.

Method A: Build on server (for simplicity)

Method B: Serve React with Nginx (optimal)

Your existing Nginx config already serves static files. For client-side routing (React Router), update config:

location / {
    try_files $uri $uri/ /index.html;
}

Edit your domain config file: sudo nano /etc/nginx/sites-available/yourdomain.com (SSL version) and add the try_files directive inside the location / block. Then sudo nginx -t && sudo systemctl reload nginx.

CI/CD suggestion (GitHub Actions)

On push, build and rsync files to server. Example workflow step:

- name: Deploy to server
  run: |
    npm run build
    rsync -avz --delete build/ deployer@yourdomain.com:/var/www/yourdomain.com/html/
After deployment, visit https://yourdomain.com --> Your React app is live with SSL!

5. Deploy Django Application (with Gunicorn & Nginx)

We'll set up Django to run behind Nginx using Gunicorn as the application server.

Environment & Dependencies

Gunicorn as a systemd service

Configure Nginx to proxy to Django

After setup, your React frontend communicates with Django API via /api/ endpoints. Both served under the same domain with SSL.
Important: For production, use PostgreSQL or MySQL instead of SQLite, set DEBUG=False, configure allowed origins with CORS if frontend is separate.

Production Best Practices & Monitoring


Quick command recap

# Firewall & SSH hardening
sudo ufw allow OpenSSH && sudo ufw enable

# Nginx + Certbot
sudo apt install nginx certbot python3-certbot-nginx

# Django service check
sudo systemctl restart gunicorn
sudo journalctl -u gunicorn -f

# React build
npm run build && sudo cp -r build/* /var/www/yourdomain.com/html/
        
Congratulations! You've configured a hardened remote server, deployed Nginx, obtained an SSL certificate, and deployed both React & Django. Your stack is production-ready.