Не запускается nginx:
.nginx/conf.template upstream backend_app { server B A C K E N D S E R V I C E N A M E : BACKEND SERVICE NAME:{BACKEND_SERVICE_PORT}; }
upstream frontend_app { server F R O N T E N D S E R V I C E N A M E : FRONTEND SERVICE NAME:{FRONTEND_SERVICE_PORT}; }
server { listen 80; server_name ${SERVER_NAME}; client_max_body_size 100M;
location / { proxy_pass http://frontend_app; proxy_set_header Host
h
o
s
t
;
p
r
o
x
y
s
e
t
h
e
a
d
e
r
X
−
R
e
a
l
−
I
P
host;proxy
s
et
h
eaderX−Real−IPremote_addr; proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto scheme; }
location {API_PREFIX} { proxy_pass http://backend_app; proxy_set_header Host host; proxy_set_header X-Real-IP
r
e
m
o
t
e
a
d
d
r
;
p
r
o
x
y
s
e
t
h
e
a
d
e
r
X
−
F
o
r
w
a
r
d
e
d
−
F
o
r
remote
a
ddr;proxy
s
et
h
eaderX−Forwarded−Forproxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 1800s; client_max_body_size 100M; proxy_connect_timeout 10s; proxy_send_timeout 60s; } }
.nginx/conf.https.template upstream backend_app { server B A C K E N D S E R V I C E N A M E : BACKEND SERVICE NAME:{BACKEND_SERVICE_PORT}; }
upstream frontend_app { server F R O N T E N D S E R V I C E N A M E : FRONTEND SERVICE NAME:{FRONTEND_SERVICE_PORT}; }
server { listen 80; server_name S E R V E R N A M E ; r e t u r n 301 h t t p s : / / SERVER NAME;return301https://host$request_uri; }
server { listen 443 ssl; server_name ${SERVER_NAME}; client_max_body_size 100M;
ssl_certificate
S
S
L
C
E
R
T
P
A
T
H
;
s
s
l
c
e
r
t
i
f
i
c
a
t
e
k
e
y
SSL
C
ERT
P
ATH;ssl
c
ertificate
k
ey{SSL_KEY_PATH};
location / { proxy_pass http://frontend_app; proxy_set_header Host
h
o
s
t
;
p
r
o
x
y
s
e
t
h
e
a
d
e
r
X
−
R
e
a
l
−
I
P
host;proxy
s
et
h
eaderX−Real−IPremote_addr; proxy_set_header X-Forwarded-For proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto scheme; }
location {API_PREFIX} { proxy_pass https://backend_app; proxy_ssl_verify off; proxy_ssl_protocols TLSv1.2 TLSv1.3; proxy_ssl_ciphers ALL; proxy_ssl_session_reuse off; proxy_set_header Host host; proxy_set_header X-Real-IP
r
e
m
o
t
e
a
d
d
r
;
p
r
o
x
y
s
e
t
h
e
a
d
e
r
X
−
F
o
r
w
a
r
d
e
d
−
F
o
r
remote
a
ddr;proxy
s
et
h
eaderX−Forwarded−Forproxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 1800s; client_max_body_size 100M; } }
#!/bin/sh SSL_DIR="/etc/nginx/ssl" LOG_FILE="/var/log/ssl_monitor.log"
apk add --no-cache openssl tzdata
month_to_number() { case $1 in Jan) echo 01;; Feb) echo 02;; Mar) echo 03;; Apr) echo 04;; May) echo 05;; Jun) echo 06;; Jul) echo 07;; Aug) echo 08;; Sep) echo 09;; Oct) echo 10;; Nov) echo 11;; Dec) echo 12;; esac }
check_cert_expiry() { if [ -f " S S L D I R / f u l l c h a i n . p e m " ] ; t h e n e x p i r y l i n e
SSL DIR/fullchain.pem"];thenexpiry line=(openssl x509 -enddate -noout -in " S S L D I R / f u l l c h a i n . p e m " ) e x p i r y d a t e
SSL DIR/fullchain.pem")expiry date={expiry_line#*=}
Исправленный парсинг даты
{
read month day time year tz
} <<-EOF
${expiry_date}
EOF
month_num=(monthtonumber"month")
Форматирование времени для busybox
iso_date="year−{month_num}-day{time}"
Конвертация с учетом ограничений Alpine
expiry_ts=(busyboxdate−D"{expiry_date}" +%s)
current_ts=(date+days(( (expiry_ts - current_ts) / 86400 ))
Исправленное перенаправление вывода
_log_entry="(date′+{days_left}"
echo "log{LOG_FILE}"
echo "${_log_entry}"
fi }
export TZ=UTC check_cert_expiry
nginx: image: "ptdockreg.ad.speechpro.com:5000/stc/infra/nginx:1.24.0-alpine" ports: - "5173:80" - "443:443" networks: - llm_network volumes: - .nginx/conf.template:/etc/nginx/conf.template - .nginx/conf.ssl.template:/etc/nginx/conf.ssl.template - .nginx/entrypoint.sh:/etc/nginx/entrypoint.sh - .config/ssl:/etc/nginx/ssl restart: always depends_on: llm-service: condition: service_healthy web: condition: service_started logging: options: max-size: 10m max-file: "3" entrypoint: [ "sh", "/etc/nginx/entrypoint.sh" ] environment: BACKEND_SERVICE_NAME: llm-service BACKEND_SERVICE_PORT: ${LITESTAR_PORT:-8001} FRONTEND_SERVICE_NAME: web FRONTEND_SERVICE_PORT: 5173 SERVER_NAME: localhost API_PREFIX: /api/ SSL_DIR: /etc/nginx/ssl
healthcheck: test: [ "CMD", "curl", "-f", "--insecure", "--max-time", "5", "http://localhost:80/health", "||", "curl", "-f", "--insecure", "--max-time", "5", "https://localhost:443/health" ] interval: 30s timeout: 10s retries: 3 start_period: 40s ошибка: 2025-05-30 10:57:05 sleep: invalid number '1 ' 2025-05-30 10:57:05 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:57:05 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:57:05 sleep: invalid number '1 ' 2025-05-30 10:57:05 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:57:05 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:57:06 sleep: invalid number '1 ' 2025-05-30 10:57:06 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:57:06 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:57:07 sleep: invalid number '1 ' 2025-05-30 10:57:07 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:57:07 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:57:08 sleep: invalid number '1 ' 2025-05-30 10:57:08 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:57:08 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:57:10 sleep: invalid number '1 ' 2025-05-30 10:57:10 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:57:10 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:57:13 sleep: invalid number '1 ' 2025-05-30 10:57:13 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:57:13 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:57:20 sleep: invalid number '1 ' 2025-05-30 10:57:20 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:57:20 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:57:33 sleep: invalid number '1 ' 2025-05-30 10:57:33 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:57:33 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:57:59 sleep: invalid number '1 ' 2025-05-30 10:57:59 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:57:59 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:58:50 sleep: invalid number '1 ' 2025-05-30 10:58:50 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:58:50 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:59:51 sleep: invalid number '1 ' 2025-05-30 10:59:51 /etc/nginx/entrypoint.sh: line 4: : not found 2025-05-30 10:59:51 /etc/nginx/entrypoint.sh: set: line 5: illegal option - 2025-05-30 10:57:05 Ожидание ...
#!/bin/sh echo "Ожидание ..." sleep 1
set -e
CONF_HTTP_TEMPLATE="/etc/nginx/conf.template" CONF_HTTPS_TEMPLATE="/etc/nginx/conf.ssl.template" NGINX_CONF="/etc/nginx/conf.d/default.conf"
echo "=== Переменные окружения ===" env | grep -E "(SSL_|BACKEND_|FRONTEND_|SERVER_|API_)" || echo "Нет SSL переменных" echo "=========================="
Функция поиска сертификатов
find_ssl_certificates() { local cert_combinations=" server.crt:server.key fullchain.pem:privkey.pem cert.pem:key.pem certificate.pem:private.key localhost.crt:localhost.key ssl.crt:ssl.key "
echo "Поиск SSL сертификатов в ${SSL_DIR}..."
for combination in certcombinations;docertfil{SSL_DIR}/combination | cut -d: -f1)"
key_file="(echo $combination | cut -d: -f2)"
if [ -f "$cert_file" ] && [ -f "$key_file" ]; then
echo "Найдена пара сертификатов: $(basename $cert_file) и $(basename $key_file)"
if [ ! -r "$cert_file" ] || [ ! -r "$key_file" ]; then
echo "ПРЕДУПРЕЖДЕНИЕ: Нет прав доступа к файлам сертификатов"
continue
fi
SSL_CERT_PATH="$cert_file"
SSL_KEY_PATH="$key_file"
return 0
fi
done
return 1
}
Выбор шаблона на основе наличия сертификатов
if find_ssl_certificates; then echo "Используется HTTPS конфигурация" TEMPLATE=${CONF_HTTPS_TEMPLATE} export SSL_CERT_PATH export SSL_KEY_PATH
Дополнительные переменные для HTTPS
envsubst '
BACKENDSERVICENAMBACKEND_SERVICE_PORT
FRONTEND_SERVICE_PORT
API_PREFIX
SSL_KEY_PATH' < {NGINX_CONF}
else echo "Используется HTTP конфигурация" TEMPLATE=${CONF_HTTP_TEMPLATE}
envsubst '
BACKENDSERVICENAMBACKEND_SERVICE_PORT
FRONTEND_SERVICE_PORT
API_PREFIX' < {NGINX_CONF}
fi
echo "Запуск Nginx..." nginx -t && nginx -g "daemon off;"