Skip to content

Commit 44ad271

Browse files
Обновлён Dockerfile для правильной подстановки переменных в конфиг nginx
1 parent 7b87dbe commit 44ad271

File tree

1 file changed

+31
-28
lines changed

1 file changed

+31
-28
lines changed

Dockerfile

+31-28
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
1+
# docker build -t nginx-proxy . && docker run -d -p 443:443 -e BACK_URI backend:12345 --name nginx-proxy nginx-proxy
2+
13
FROM ghcr.io/devops-from-root/alpine:main
24

35
# Устанавливаем значения переменных
4-
ARG BACK_URI=localhost
5-
ENV BACK_URI=${BACK_URI}
6+
ENV BACK_URI=localhost
67

78
# Устанавливаем необходимые пакеты
8-
RUN apk add --no-cache openssl netcat-openbsd nginx
9+
RUN apk add --no-cache openssl curl netcat-openbsd nginx
910

1011
# Создаем директорию для сертификатов
1112
RUN mkdir -p /etc/nginx/ssl
1213

1314
# Генерируем самоподписанный сертификат
1415
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/nginx.key -out /etc/nginx/ssl/nginx.crt -subj "/CN=localhost"
1516

16-
# Создаем конфигурацию nginx через echo
17-
RUN cat <<EOF > /etc/nginx/nginx.conf
18-
events {}
19-
20-
http {
21-
server {
22-
listen 443 ssl;
23-
server_name _default;
24-
25-
ssl_certificate /etc/nginx/ssl/nginx.crt;
26-
ssl_certificate_key /etc/nginx/ssl/nginx.key;
27-
28-
location / {
29-
proxy_pass http://${BACK_URI};
30-
proxy_set_header Host \$host;
31-
proxy_set_header X-Real-IP \$remote_addr;
32-
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
33-
proxy_set_header X-Forwarded-Proto \$scheme;
34-
}
35-
}
36-
}
37-
EOF
38-
39-
# Запуск Nginx
40-
CMD ["nginx", "-g", "daemon off;"]
17+
# Генерируем конфиг nginx
18+
RUN echo -e "events {}\n\
19+
http {\n\
20+
server {\n\
21+
listen 443 ssl;\n\
22+
ssl_certificate /etc/nginx/ssl/nginx.crt;\n\
23+
ssl_certificate_key /etc/nginx/ssl/nginx.key;\n\
24+
ssl_protocols TLSv1.2 TLSv1.3;\
25+
ssl_ciphers 'TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384';\
26+
ssl_prefer_server_ciphers on;\
27+
location / {\n\
28+
proxy_pass http://localhost;\n\
29+
proxy_set_header Host \$host;\n\
30+
proxy_set_header X-Real-IP \$remote_addr;\n\
31+
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;\n\
32+
proxy_set_header X-Forwarded-Proto \$scheme;\n\
33+
}\n\
34+
access_log /proc/self/fd/1;\
35+
error_log /proc/self/fd/2;\
36+
}\n\
37+
}" > /etc/nginx/nginx.conf
38+
39+
# Открываем порт 443
40+
EXPOSE 443
41+
42+
# Заменяем в конфиге localhost на значение переменной BACK_URI и запускаем nginx
43+
CMD /bin/sh -c "sed -i 's/localhost/'$BACK_URI'/g' /etc/nginx/nginx.conf && nginx -g 'daemon off;'"

0 commit comments

Comments
 (0)