# 🚀 PM2 + Nginx Proxy Setup Guide

In a PM2 reverse proxy setup, **Nginx proxies all web requests directly to PM2 (`http://127.0.0.1:8000`)**, while serving static assets (CSS, JS, images, uploads) directly from disk for high speed.

---

## 📄 Nginx Configuration (`deploy/nginx.conf`)

```nginx
server {
    listen 80;
    server_name api-staging.volubit.id;

    root /var/www/volubit-be/public;

    # Static assets (served directly if they exist, proxy fallback if dynamic)
    location ~* \.(jpg|jpeg|gif|png|css|js|ico|webp|svg|woff|woff2|ttf|eot)$ {
        expires 365d;
        try_files $uri @proxy;
    }

    location /storage/ {
        alias /var/www/volubit-be/storage/app/public/;
        expires 30d;
    }

    # All web requests proxy directly to PM2 (Port 8000)
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        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;
    }

    location @proxy {
        proxy_pass http://127.0.0.1:8000;
        proxy_http_version 1.1;
        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;
    }
}
```

---

## 🛠️ Update Command on VPS

Update your Nginx config file on VPS and reload:

```bash
sudo nano /etc/nginx/sites-available/volubit-be.conf
# Paste the updated config above

sudo nginx -t && sudo systemctl reload nginx
```
