[READ-ONLY] Mirror of https://github.com/thoda-dev/scripts. custom scripts
0

Configure Feed

Select the types of activity you want to include in your feed.

fix et ajout docker

Thomas (Dec 9, 2025, 5:00 PM +0100) befe42ee 3f1c53d3

+157 -1
+1 -1
set_new_nginx_app.sh
··· 76 76 sudo systemctl start nginx 77 77 78 78 # ------------------------------ 79 - # Configurer Nginx pour l'app (wildcard) 79 + # Configurer Nginx pour l'app (wildcard) sur port 80 only le temps de mettre en place SSL 80 80 # ------------------------------ 81 81 NGINX_CONF="/etc/nginx/sites-available/$DOMAIN" 82 82 sudo tee $NGINX_CONF > /dev/null <<EOF
+156
set_new_nginx_docker_app.sh
··· 1 + #!/bin/bash 2 + 3 + # ------------------------------ 4 + # Script réutilisable Node.js LTS + pnpm + Nginx + Certbot Cloudflare 5 + # Arguments : 6 + # $1 = Domaine (ex: exemple.com) 7 + # $2 = Port Node.js (ex: 3000) 8 + # $3 = Email pour SSL (ex: email@example.com) 9 + # ------------------------------ 10 + 11 + if [ "$#" -ne 3 ]; then 12 + echo "Usage: $0 <domain> <app_port> <email>" 13 + exit 1 14 + fi 15 + 16 + DOMAIN="$1" 17 + APP_PORT="$2" 18 + EMAIL="$3" 19 + CLOUDFLARE_CREDENTIALS="$HOME/.secrets/certbot/cloudflare.ini" 20 + 21 + echo "⚙️ Configuration pour :" 22 + echo "Domaine: $DOMAIN" 23 + echo "Port Node.js: $APP_PORT" 24 + echo "Email SSL: $EMAIL" 25 + 26 + # ------------------------------ 27 + # Fonction pour installer un paquet si absent 28 + # ------------------------------ 29 + install_if_missing() { 30 + if ! command -v $1 &> /dev/null; then 31 + echo "Installation de $1..." 32 + sudo apt install -y $2 33 + else 34 + echo "$1 déjà installé, skipping..." 35 + fi 36 + } 37 + 38 + # ------------------------------ 39 + # Mise à jour système 40 + # ------------------------------ 41 + sudo apt update && sudo apt upgrade -y 42 + 43 + # Installer dépendances de base 44 + install_if_missing curl curl 45 + install_if_missing git git 46 + install_if_missing build-essential build-essential 47 + install_if_missing software-properties-common software-properties-common 48 + 49 + # Installer Node.js LTS si absent 50 + if ! command -v node &> /dev/null; then 51 + curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - 52 + sudo apt install -y nodejs 53 + else 54 + echo "Node.js déjà installé, skipping..." 55 + fi 56 + 57 + # Installer pnpm si absent 58 + if ! command -v pnpm &> /dev/null; then 59 + sudo npm install -g pnpm 60 + else 61 + echo "pnpm déjà installé, skipping..." 62 + fi 63 + 64 + # Installer docker et docker-compose si absent 65 + install_if_missing docker docker.io 66 + install_if_missing docker-compose docker-compose 67 + 68 + # Installer Nginx si absent 69 + install_if_missing nginx nginx 70 + sudo systemctl enable nginx 71 + sudo systemctl start nginx 72 + 73 + # ------------------------------ 74 + # Configurer Nginx pour l'app (wildcard) sur port 80 only le temps de mettre en place SSL 75 + # ------------------------------ 76 + NGINX_CONF="/etc/nginx/sites-available/$DOMAIN" 77 + sudo tee $NGINX_CONF > /dev/null <<EOF 78 + server { 79 + listen 80; 80 + server_name $DOMAIN *.$DOMAIN; 81 + 82 + location / { 83 + proxy_pass http://127.0.0.1:$APP_PORT; 84 + proxy_http_version 1.1; 85 + proxy_set_header Upgrade \$http_upgrade; 86 + proxy_set_header Connection 'upgrade'; 87 + proxy_set_header Host \$host; 88 + proxy_cache_bypass \$http_upgrade; 89 + } 90 + } 91 + EOF 92 + 93 + sudo ln -sf $NGINX_CONF /etc/nginx/sites-enabled/ 94 + sudo nginx -t && sudo systemctl reload nginx 95 + 96 + # ------------------------------ 97 + # Installer Certbot et plugin Cloudflare 98 + # ------------------------------ 99 + install_if_missing certbot certbot 100 + install_if_missing python3-certbot-dns-cloudflare python3-certbot-dns-cloudflare 101 + 102 + # Générer certificat wildcard SSL via Cloudflare si absent 103 + if [ ! -d "/etc/letsencrypt/live/$DOMAIN" ]; then 104 + sudo certbot certonly \ 105 + --dns-cloudflare \ 106 + --dns-cloudflare-credentials $CLOUDFLARE_CREDENTIALS \ 107 + -d $DOMAIN -d *.$DOMAIN \ 108 + -m $EMAIL \ 109 + --agree-tos \ 110 + --non-interactive 111 + else 112 + echo "Certificat SSL déjà existant pour $DOMAIN, skipping..." 113 + fi 114 + 115 + # Configurer Nginx pour SSL 116 + sudo tee /etc/nginx/sites-available/$DOMAIN > /dev/null <<EOF 117 + server { 118 + listen 80; 119 + server_name $DOMAIN *.$DOMAIN; 120 + return 301 https://\$host\$request_uri; 121 + } 122 + 123 + server { 124 + listen 443 ssl; 125 + server_name $DOMAIN *.$DOMAIN; 126 + 127 + ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem; 128 + ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem; 129 + 130 + location / { 131 + proxy_pass http://127.0.0.1:$APP_PORT; 132 + proxy_http_version 1.1; 133 + proxy_set_header Upgrade \$http_upgrade; 134 + proxy_set_header Connection 'upgrade'; 135 + proxy_set_header Host \$host; 136 + proxy_cache_bypass \$http_upgrade; 137 + proxy_redirect off; 138 + proxy_set_header X-Real-IP \$remote_addr; 139 + proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; 140 + proxy_set_header X-Real-IP \$remote_addr; 141 + 142 + # Pour les requêtes de streaming 143 + proxy_buffering off; 144 + proxy_cache off; 145 + proxy_request_buffering off; 146 + proxy_read_timeout 3600s; 147 + proxy_send_timeout 3600s; 148 + } 149 + } 150 + EOF 151 + 152 + sudo nginx -t && sudo systemctl reload nginx 153 + 154 + echo "✅ Installation terminée !" 155 + echo "Port Node.js: $APP_PORT" 156 + echo "Nginx configuré avec SSL wildcard pour $DOMAIN et *.$DOMAIN"