fix: Separar configuração Nginx do HotWives para não afetar mentorado.tech
- 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
This commit is contained in:
301
ATIVAR_NGINX.md
Normal file
301
ATIVAR_NGINX.md
Normal file
@@ -0,0 +1,301 @@
|
|||||||
|
# ⚠️ 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! 🚀**
|
||||||
|
|
||||||
134
nginx-hotwives.conf
Normal file
134
nginx-hotwives.conf
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
# CONFIGURAÇÃO NGINX PARA HOTWIVES
|
||||||
|
# IMPORTANTE: NÃO ATIVE AINDA! Mentorado.tech está em produção.
|
||||||
|
#
|
||||||
|
# Este arquivo está em /var/www/hotwives/nginx-hotwives.conf
|
||||||
|
#
|
||||||
|
# INSTRUÇÕES PARA ATIVAR (apenas quando estiver pronto):
|
||||||
|
# 1. Certifique-se que hotwives.com.br está apontando para este servidor
|
||||||
|
# 2. sudo cp /var/www/hotwives/nginx-hotwives.conf /etc/nginx/sites-available/hotwives
|
||||||
|
# 3. sudo ln -s /etc/nginx/sites-available/hotwives /etc/nginx/sites-enabled/
|
||||||
|
# 4. sudo nginx -t
|
||||||
|
# 5. sudo certbot --nginx -d hotwives.com.br -d www.hotwives.com.br
|
||||||
|
# 6. sudo systemctl reload nginx
|
||||||
|
|
||||||
|
# HTTP - Redireciona para HTTPS
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name hotwives.com.br www.hotwives.com.br;
|
||||||
|
|
||||||
|
# Redirecionar para HTTPS (depois de configurar SSL)
|
||||||
|
return 301 https://$server_name$request_uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
# HTTPS - Configuração principal
|
||||||
|
server {
|
||||||
|
listen 443 ssl http2;
|
||||||
|
server_name hotwives.com.br www.hotwives.com.br;
|
||||||
|
|
||||||
|
# Certificados SSL - O Certbot irá adicionar/atualizar estas linhas automaticamente
|
||||||
|
# ssl_certificate /etc/letsencrypt/live/hotwives.com.br/fullchain.pem;
|
||||||
|
# ssl_certificate_key /etc/letsencrypt/live/hotwives.com.br/privkey.pem;
|
||||||
|
# include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||||
|
# ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||||
|
|
||||||
|
# Configurações SSL básicas (até o Certbot configurar)
|
||||||
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||||||
|
ssl_ciphers HIGH:!aNULL:!MD5;
|
||||||
|
ssl_prefer_server_ciphers on;
|
||||||
|
|
||||||
|
# Logs separados
|
||||||
|
access_log /var/log/nginx/hotwives-access.log;
|
||||||
|
error_log /var/log/nginx/hotwives-error.log;
|
||||||
|
|
||||||
|
# Frontend Next.js - Porta 3000
|
||||||
|
location / {
|
||||||
|
proxy_pass http://localhost:3000;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_cache_bypass $http_upgrade;
|
||||||
|
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;
|
||||||
|
|
||||||
|
# Timeouts
|
||||||
|
proxy_connect_timeout 60s;
|
||||||
|
proxy_send_timeout 60s;
|
||||||
|
proxy_read_timeout 60s;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Backend API - Porta 3001
|
||||||
|
location /api {
|
||||||
|
proxy_pass http://localhost:3001;
|
||||||
|
proxy_http_version 1.1;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection 'upgrade';
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
proxy_cache_bypass $http_upgrade;
|
||||||
|
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;
|
||||||
|
|
||||||
|
# CORS headers (se necessário)
|
||||||
|
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||||
|
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
|
||||||
|
add_header 'Access-Control-Allow-Headers' 'Authorization, Content-Type' always;
|
||||||
|
|
||||||
|
if ($request_method = 'OPTIONS') {
|
||||||
|
return 204;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Timeouts
|
||||||
|
proxy_connect_timeout 60s;
|
||||||
|
proxy_send_timeout 60s;
|
||||||
|
proxy_read_timeout 60s;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Socket.IO - WebSocket
|
||||||
|
location /socket.io {
|
||||||
|
proxy_pass http://localhost:3001;
|
||||||
|
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;
|
||||||
|
|
||||||
|
# Timeouts maiores para WebSocket
|
||||||
|
proxy_connect_timeout 7d;
|
||||||
|
proxy_send_timeout 7d;
|
||||||
|
proxy_read_timeout 7d;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Uploads - Servir arquivos estáticos
|
||||||
|
location /uploads {
|
||||||
|
alias /var/www/hotwives/backend/uploads;
|
||||||
|
expires 30d;
|
||||||
|
add_header Cache-Control "public, immutable";
|
||||||
|
|
||||||
|
# Segurança
|
||||||
|
location ~ \.(php|phtml|php3|php4|php5|jsp)$ {
|
||||||
|
deny all;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Tamanho máximo de upload
|
||||||
|
client_max_body_size 10M;
|
||||||
|
client_body_buffer_size 128k;
|
||||||
|
|
||||||
|
# Compressão Gzip
|
||||||
|
gzip on;
|
||||||
|
gzip_vary on;
|
||||||
|
gzip_min_length 1024;
|
||||||
|
gzip_comp_level 6;
|
||||||
|
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml+rss application/json application/javascript;
|
||||||
|
|
||||||
|
# Headers de segurança
|
||||||
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||||
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
|
add_header X-XSS-Protection "1; mode=block" always;
|
||||||
|
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user