# Server Setup Guide — SuperVPN Proxy Website

## Overview

Static marketing website built with **Next.js 16** (React 19, TypeScript, Tailwind CSS 4).  
Single-page landing — no database, no backend API, no authentication.

---

## Prerequisites

| Requirement | Minimum | Recommended |
|---|---|---|
| **Node.js** | 18.x | 20.x LTS |
| **npm** | 9.x | 10.x |
| **RAM** | 512 MB | 1 GB |
| **Disk** | 500 MB | 1 GB |
| **OS** | Ubuntu 20.04+ / Amazon Linux 2 | Ubuntu 22.04 LTS |

---

## 1. Clone & Install

```bash
git clone <repo-url> /var/www/vpn-website
cd /var/www/vpn-website
npm install
```

---

## 2. Configure for Production

### Set Environment to Production

Edit `lib/site-config.ts` and update:

```typescript
// Change "staging" to "production"
export const ENV: "staging" | "production" = "production";
```

This switches all payment URLs from staging (test) to production (live Razorpay).

### Update Site Config

In the same file (`lib/site-config.ts`), set:

| Field | What to set |
|---|---|
| `downloadUrl` | Direct URL to the `.dmg` download file |
| `url` | Production domain (e.g., `https://supervpnproxy.com`) |
| `supportEmail` | Production support email |

---

## 3. Build

```bash
npm run build
```

This creates an optimized production build in the `.next/` directory.  
Build should complete with **no errors**. Expected output: `Route (app) ... Size ... First Load JS`.

---

## 4. Run the Server

### Option A: Direct (Quick Test)

```bash
npm run start -- -H 0.0.0.0 -p 3000
```

Server runs on port 3000. Access at `http://<server-ip>:3000`.

### Option B: PM2 (Recommended for Production)

```bash
# Install PM2 globally
npm install -g pm2

# Start the app
pm2 start npm --name "vpn-website" -- start -- -H 0.0.0.0 -p 3000

# Auto-restart on server reboot
pm2 startup
pm2 save

# Useful commands
pm2 status              # Check status
pm2 logs vpn-website    # View logs
pm2 restart vpn-website # Restart
pm2 stop vpn-website    # Stop
```

### Option C: systemd Service

Create `/etc/systemd/system/vpn-website.service`:

```ini
[Unit]
Description=SuperVPN Proxy Website
After=network.target

[Service]
Type=simple
User=www-data
WorkingDirectory=/var/www/vpn-website
ExecStart=/usr/bin/npm run start -- -H 0.0.0.0 -p 3000
Restart=on-failure
RestartSec=5
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target
```

Then:

```bash
sudo systemctl daemon-reload
sudo systemctl enable vpn-website
sudo systemctl start vpn-website

# Check status
sudo systemctl status vpn-website
```

---

## 5. Nginx Reverse Proxy

Install Nginx and create `/etc/nginx/sites-available/vpn-website`:

```nginx
server {
    listen 80;
    server_name supervpnproxy.com www.supervpnproxy.com;

    location / {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        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;
        proxy_cache_bypass $http_upgrade;
    }
}
```

Enable and restart:

```bash
sudo ln -s /etc/nginx/sites-available/vpn-website /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
```

---

## 6. SSL (HTTPS)

```bash
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d supervpnproxy.com -d www.supervpnproxy.com
```

Certbot auto-renews. Verify with:

```bash
sudo certbot renew --dry-run
```

---

## 7. Deployment Updates

When deploying new code:

```bash
cd /var/www/vpn-website
git pull origin main
npm install
npm run build

# Restart the server (pick one based on your setup)
pm2 restart vpn-website          # If using PM2
sudo systemctl restart vpn-website  # If using systemd
```

---

## Port Summary

| Service | Port | Notes |
|---|---|---|
| Next.js | 3000 | Internal only (behind Nginx) |
| Nginx | 80 | HTTP (redirects to 443) |
| Nginx | 443 | HTTPS |

### Firewall

```bash
sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 22    # SSH
sudo ufw enable
```

Do **not** expose port 3000 publicly — Nginx proxies to it.

---

## Health Check

```bash
curl -I http://localhost:3000
```

Expected: `HTTP/1.1 200 OK`

---

## Troubleshooting

| Issue | Fix |
|---|---|
| `npm run build` fails | Check Node.js version (`node -v`). Must be 18+. |
| Site loads but no interactivity | Ensure Nginx passes headers correctly (see proxy config above) |
| Payment goes to test/staging | Change `ENV` to `"production"` in `lib/site-config.ts` and rebuild |
| Port 3000 already in use | `lsof -i :3000` to find the process, kill it, then restart |
| SSL certificate expired | Run `sudo certbot renew` |
