1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00
Files
AdministrationItDepartmens/docker/nginx/entrypoint.sh
2025-01-04 05:20:56 +06:00

53 lines
1.5 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# Домены для SSL-сертификата
domains="itformhelp.ru www.itformhelp.ru"
email="admin@itformhelp.ru"
# Функция для получения сертификата
get_certificate() {
echo "Requesting Let's Encrypt certificate for $domains ..."
# Создаем временный конфиг nginx для валидации certbot
cat > /etc/nginx/conf.d/temp.conf << EOF
server {
listen 80;
server_name $domains;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://\$host\$request_uri;
}
}
EOF
# Перезапускаем nginx с временным конфигом
nginx -t && nginx -s reload
# Запрашиваем сертификат
certbot certonly --webroot \
--webroot-path=/var/www/certbot \
--email $email \
--agree-tos \
--no-eff-email \
--force-renewal \
-d $(echo $domains | sed 's/ / -d /g')
# Удаляем временный конфиг
rm /etc/nginx/conf.d/temp.conf
}
# Проверяем наличие сертификата
if [ ! -d "/etc/letsencrypt/live/itformhelp.ru" ]; then
get_certificate
fi
# Запускаем фоновый процесс для автоматического обновления сертификатов
while :; do
certbot renew --deploy-hook "nginx -s reload"
sleep 12h
done &
# Запускаем nginx
nginx -g "daemon off;"