# ✅ Solução do Erro 503

## 🔍 Problemas Identificados

1. **Modo de manutenção ativo** - Sistema está em modo de manutenção
2. **Backend não está rodando na porta 8080** - Nginx não consegue se conectar ao backend

## 🚀 Solução Rápida

Execute os comandos abaixo **na ordem**:

### **PASSO 1: Remover Modo de Manutenção**

```bash
cd /var/www/gestorstream/backend
rm -f storage/framework/down
```

### **PASSO 2: Verificar Configuração do Nginx**

```bash
# Ver configuração do site
cat /etc/nginx/sites-enabled/gestorstream | grep -A 10 "location /api"
```

### **PASSO 3: Verificar se há processo PHP rodando na porta 8000**

```bash
# Ver processo na porta 8000
ps aux | grep 39357
netstat -tlnp | grep 8000
```

### **PASSO 4: Verificar configuração do Nginx para backend**

O Nginx precisa estar configurado para fazer proxy para o backend. Verifique:

```bash
cat /etc/nginx/sites-enabled/gestorstream
```

Procure por algo como:
```nginx
location /api {
    try_files $uri $uri/ /index.php?$query_string;
    # ou
    proxy_pass http://127.0.0.1:8000;
}
```

### **PASSO 5: Reiniciar Serviços**

```bash
# Reiniciar PHP-FPM
sudo systemctl restart php8.2-fpm

# Reiniciar Nginx
sudo systemctl restart nginx

# Verificar status
sudo systemctl status php8.2-fpm
sudo systemctl status nginx
```

### **PASSO 6: Testar Backend**

```bash
# Testar se o backend responde via PHP-FPM
curl -I http://localhost/api/v1/health

# Ou testar diretamente
cd /var/www/gestorstream/backend
php artisan serve --host=127.0.0.1 --port=8000 &
```

### **PASSO 7: Verificar Logs Novamente**

```bash
# Ver se ainda há erros
tail -20 /var/log/nginx/error.log
tail -20 /var/www/gestorstream/backend/storage/logs/laravel.log
```

---

## 📋 Comandos Completos (Copie e Cole)

```bash
# 1. Remover modo de manutenção
cd /var/www/gestorstream/backend
rm -f storage/framework/down

# 2. Verificar configuração do Nginx
cat /etc/nginx/sites-enabled/gestorstream | grep -A 20 "location /api"

# 3. Reiniciar serviços
sudo systemctl restart php8.2-fpm
sudo systemctl restart nginx

# 4. Testar
curl -I http://localhost/api/v1/health
curl -I https://gestor.jf.eng.br/api/v1/health

# 5. Verificar logs
tail -10 /var/log/nginx/error.log
```

---

## 🔧 Se Ainda Não Funcionar

### Verificar Configuração Completa do Nginx

```bash
# Ver arquivo completo
cat /etc/nginx/sites-enabled/gestorstream
```

O arquivo deve ter algo como:

```nginx
server {
    listen 80;
    listen [::]:80;
    server_name gestor.jf.eng.br;
    
    root /var/www/gestorstream/frontend/dist;
    index index.html;
    
    # API - Backend Laravel
    location /api {
        try_files $uri $uri/ /index.php?$query_string;
    }
    
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    
    # Frontend
    location / {
        try_files $uri $uri/ /index.html;
    }
}
```

---

## ⚠️ Importante

O backend Laravel deve estar configurado para usar **PHP-FPM** (não precisa rodar na porta 8080). O Nginx deve fazer proxy das requisições `/api` para o PHP-FPM.

