-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-https.sh
More file actions
78 lines (64 loc) · 2.21 KB
/
Copy pathsetup-https.sh
File metadata and controls
78 lines (64 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
set -e
DOMAIN="54-196-48-214.sslip.io"
EMAIL="mariaeduarda.devcloud@gmail.com"
echo "🔐 CONFIGURANDO HTTPS para $DOMAIN"
# 1. Atualizar sistema e instalar dependências
echo "📦 Instalando Nginx e Certbot..."
sudo apt update -y
sudo apt install -y nginx certbot python3-certbot-nginx
# 2. Liberar portas no firewall
sudo ufw allow 'Nginx Full' 2>/dev/null || true
sudo ufw allow 80/tcp 2>/dev/null || true
sudo ufw allow 443/tcp 2>/dev/null || true
# 3. Configurar Nginx como proxy reverso para o Docker
sudo bash -c "cat > /etc/nginx/sites-available/$DOMAIN" <<'NGINXEOF'
server {
listen 80;
server_name 54-196-48-214.sslip.io;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $http_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_read_timeout 300;
proxy_connect_timeout 300;
}
}
NGINXEOF
# 4. Ativar site e remover default
sudo mkdir -p /var/www/certbot
sudo ln -sf /etc/nginx/sites-available/$DOMAIN /etc/nginx/sites-enabled/$DOMAIN
sudo rm -f /etc/nginx/sites-enabled/default
# 5. Testar e reiniciar Nginx
echo "🔄 Reiniciando Nginx..."
sudo nginx -t
sudo systemctl restart nginx
# 6. Gerar certificado SSL com Let's Encrypt
echo "🔑 Gerando certificado SSL..."
sudo certbot --nginx \
-d $DOMAIN \
--non-interactive \
--agree-tos \
-m $EMAIL \
--redirect
# 7. Reiniciar Docker com nova porta
echo "🐳 Reiniciando containers Docker..."
cd /var/www/aws-rails-cloud-deploy
docker compose --env-file .env.production down
docker compose --env-file .env.production up -d
# 8. Renovação automática
echo "🔁 Configurando renovação automática..."
(sudo crontab -l 2>/dev/null; echo "0 12 * * * /usr/bin/certbot renew --quiet && systemctl reload nginx") | sudo crontab -
# 9. Teste final
echo "⏳ Aguardando 10s..."
sleep 10
echo "🧪 Testando HTTPS..."
curl -s -o /dev/null -w "HTTP status: %{http_code}\n" https://$DOMAIN
echo ""
echo "✅ HTTPS configurado com sucesso!"
echo "🌐 Acesse: https://$DOMAIN"