- Remover configuração ativa do nginx - Criar arquivo nginx-hotwives.conf separado em /var/www/hotwives/ - Adicionar guia completo ATIVAR_NGINX.md com instruções seguras - HotWives usará portas 3000/3001 (mentorado usa 3007) - Configuração só será ativada manualmente quando DNS estiver pronto
302 lines
6.0 KiB
Markdown
302 lines
6.0 KiB
Markdown
# ⚠️ Como Ativar o Nginx para HotWives (SEM AFETAR MENTORADO.TECH)
|
|
|
|
## ⚠️ IMPORTANTE - LEIA ANTES DE EXECUTAR
|
|
|
|
O servidor já tem o **mentorado.tech** rodando em PRODUÇÃO na porta 3007.
|
|
O HotWives usará portas DIFERENTES (3000 e 3001) para não haver conflito.
|
|
|
|
## Pré-requisitos
|
|
|
|
Antes de ativar o nginx do HotWives:
|
|
|
|
1. ✅ **DNS configurado**: hotwives.com.br deve estar apontando para este servidor
|
|
2. ✅ **Portas livres**: Verificar se portas 3000 e 3001 estão disponíveis
|
|
3. ✅ **Aplicações rodando**: Backend e Frontend do HotWives devem estar ativos
|
|
4. ✅ **Banco configurado**: PostgreSQL configurado e migrações executadas
|
|
|
|
## Verificações de Segurança
|
|
|
|
### 1. Verificar se portas 3000 e 3001 estão livres
|
|
|
|
```bash
|
|
# Verificar portas em uso
|
|
sudo netstat -tulpn | grep -E ':(3000|3001|3007)'
|
|
|
|
# Você deve ver apenas a 3007 (mentorado) ativa
|
|
# Se 3000 ou 3001 estiverem em uso, algo já está rodando nelas
|
|
```
|
|
|
|
### 2. Verificar DNS
|
|
|
|
```bash
|
|
# Verificar se hotwives.com.br aponta para este servidor
|
|
dig hotwives.com.br +short
|
|
nslookup hotwives.com.br
|
|
|
|
# O IP retornado deve ser o IP deste servidor
|
|
```
|
|
|
|
### 3. Verificar configuração atual do Nginx
|
|
|
|
```bash
|
|
# Ver sites ativos (NÃO deve ter hotwives ainda)
|
|
ls -la /etc/nginx/sites-enabled/
|
|
|
|
# Testar configuração atual
|
|
sudo nginx -t
|
|
```
|
|
|
|
## Instalação e Configuração
|
|
|
|
### Passo 1: Preparar o Ambiente
|
|
|
|
```bash
|
|
cd /var/www/hotwives
|
|
|
|
# Instalar dependências
|
|
npm install
|
|
cd backend && npm install
|
|
cd ../frontend && npm install
|
|
```
|
|
|
|
### Passo 2: Configurar Banco de Dados
|
|
|
|
```bash
|
|
cd /var/www/hotwives/backend
|
|
|
|
# Copiar e editar .env
|
|
cp .env.example .env
|
|
nano .env
|
|
|
|
# Configure:
|
|
# - DATABASE_URL com suas credenciais PostgreSQL
|
|
# - JWT_SECRET com uma chave forte aleatória
|
|
# - SMTP para emails
|
|
# - Todas as outras variáveis
|
|
|
|
# Executar migrações
|
|
npx prisma generate
|
|
npx prisma migrate deploy
|
|
```
|
|
|
|
### Passo 3: Build das Aplicações
|
|
|
|
```bash
|
|
# Backend
|
|
cd /var/www/hotwives/backend
|
|
npm run build
|
|
|
|
# Frontend
|
|
cd /var/www/hotwives/frontend
|
|
npm run build
|
|
```
|
|
|
|
### Passo 4: Testar Aplicações Localmente
|
|
|
|
```bash
|
|
# Em um terminal, inicie o backend:
|
|
cd /var/www/hotwives/backend
|
|
npm start
|
|
|
|
# Em outro terminal, inicie o frontend:
|
|
cd /var/www/hotwives/frontend
|
|
npm start
|
|
|
|
# Teste acessando:
|
|
# http://localhost:3000 (frontend)
|
|
# http://localhost:3001/health (backend)
|
|
```
|
|
|
|
### Passo 5: Configurar PM2 (Gerenciamento de Processos)
|
|
|
|
```bash
|
|
# Instalar PM2 globalmente (se ainda não tiver)
|
|
sudo npm install -g pm2
|
|
|
|
# Iniciar aplicações
|
|
cd /var/www/hotwives
|
|
pm2 start ecosystem.config.js
|
|
|
|
# Verificar status
|
|
pm2 status
|
|
|
|
# Você deve ver:
|
|
# - hotwives-backend (rodando)
|
|
# - hotwives-frontend (rodando)
|
|
|
|
# Salvar configuração
|
|
pm2 save
|
|
|
|
# Configurar para iniciar no boot
|
|
pm2 startup
|
|
# Execute o comando que o PM2 mostrar
|
|
```
|
|
|
|
### Passo 6: Ativar Configuração do Nginx
|
|
|
|
```bash
|
|
# Copiar configuração para sites-available
|
|
sudo cp /var/www/hotwives/nginx-hotwives.conf /etc/nginx/sites-available/hotwives
|
|
|
|
# Criar link simbólico para ativar
|
|
sudo ln -s /etc/nginx/sites-available/hotwives /etc/nginx/sites-enabled/
|
|
|
|
# IMPORTANTE: Testar configuração ANTES de recarregar
|
|
sudo nginx -t
|
|
|
|
# Se tudo estiver OK, você verá:
|
|
# nginx: configuration file /etc/nginx/nginx.conf test is successful
|
|
```
|
|
|
|
### Passo 7: Configurar SSL com Certbot
|
|
|
|
```bash
|
|
# Instalar Certbot (se ainda não tiver)
|
|
sudo apt install -y certbot python3-certbot-nginx
|
|
|
|
# Obter e configurar certificado SSL
|
|
sudo certbot --nginx -d hotwives.com.br -d www.hotwives.com.br
|
|
|
|
# Siga as instruções do Certbot
|
|
# Ele irá:
|
|
# 1. Validar o domínio
|
|
# 2. Obter certificado SSL
|
|
# 3. Atualizar automaticamente o arquivo de configuração do nginx
|
|
# 4. Configurar redirecionamento HTTPS
|
|
```
|
|
|
|
### Passo 8: Recarregar Nginx
|
|
|
|
```bash
|
|
# Recarregar nginx (sem afetar mentorado.tech)
|
|
sudo systemctl reload nginx
|
|
|
|
# OU, se preferir restart:
|
|
sudo systemctl restart nginx
|
|
|
|
# Verificar status
|
|
sudo systemctl status nginx
|
|
```
|
|
|
|
## Verificação Final
|
|
|
|
```bash
|
|
# 1. Ver todos os sites ativos
|
|
ls -la /etc/nginx/sites-enabled/
|
|
|
|
# Você deve ver:
|
|
# - mentorado (mentorado.tech - porta 3007)
|
|
# - vida180 (se ativo)
|
|
# - hotwives (hotwives.com.br - portas 3000/3001)
|
|
|
|
# 2. Verificar portas em uso
|
|
sudo netstat -tulpn | grep nginx
|
|
|
|
# 3. Ver processos PM2
|
|
pm2 status
|
|
|
|
# 4. Testar acesso
|
|
curl -I https://hotwives.com.br
|
|
curl https://hotwives.com.br/api/health
|
|
```
|
|
|
|
## Mapa de Portas
|
|
|
|
Para referência, após ativação:
|
|
|
|
| Serviço | Porta | URL |
|
|
|---------|-------|-----|
|
|
| Mentorado.tech | 3007 | https://mentorado.tech |
|
|
| HotWives Frontend | 3000 | https://hotwives.com.br |
|
|
| HotWives Backend | 3001 | https://hotwives.com.br/api |
|
|
|
|
## Logs
|
|
|
|
```bash
|
|
# Logs do Nginx
|
|
sudo tail -f /var/log/nginx/hotwives-access.log
|
|
sudo tail -f /var/log/nginx/hotwives-error.log
|
|
|
|
# Logs do PM2
|
|
pm2 logs hotwives-backend
|
|
pm2 logs hotwives-frontend
|
|
|
|
# Ver todos os logs
|
|
pm2 logs
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Erro 502 Bad Gateway
|
|
|
|
```bash
|
|
# Verificar se aplicações estão rodando
|
|
pm2 status
|
|
|
|
# Verificar logs
|
|
pm2 logs hotwives-backend
|
|
pm2 logs hotwives-frontend
|
|
|
|
# Reiniciar se necessário
|
|
pm2 restart hotwives-backend
|
|
pm2 restart hotwives-frontend
|
|
```
|
|
|
|
### Conflito de Porta
|
|
|
|
```bash
|
|
# Ver o que está usando a porta
|
|
sudo lsof -i :3000
|
|
sudo lsof -i :3001
|
|
|
|
# Matar processo se necessário
|
|
sudo kill -9 <PID>
|
|
```
|
|
|
|
### SSL não funciona
|
|
|
|
```bash
|
|
# Verificar certificados
|
|
sudo certbot certificates
|
|
|
|
# Renovar se necessário
|
|
sudo certbot renew --dry-run
|
|
sudo certbot renew
|
|
```
|
|
|
|
## Desativar (Se Necessário)
|
|
|
|
```bash
|
|
# Parar aplicações
|
|
pm2 stop hotwives-backend
|
|
pm2 stop hotwives-frontend
|
|
|
|
# Desativar nginx
|
|
sudo rm /etc/nginx/sites-enabled/hotwives
|
|
sudo nginx -t
|
|
sudo systemctl reload nginx
|
|
```
|
|
|
|
## ⚠️ Lembrete Final
|
|
|
|
**SEMPRE** teste a configuração do nginx antes de recarregar:
|
|
|
|
```bash
|
|
sudo nginx -t
|
|
```
|
|
|
|
Se aparecer erro, **NÃO** recarregue o nginx. Corrija o erro primeiro.
|
|
|
|
## Suporte
|
|
|
|
Se tiver problemas:
|
|
1. Verifique os logs do nginx e PM2
|
|
2. Confirme que todas as portas estão corretas
|
|
3. Verifique que o DNS está apontando corretamente
|
|
4. Teste cada componente individualmente
|
|
|
|
---
|
|
|
|
**Boa sorte! 🚀**
|
|
|