1
+ # docker build -t nginx-proxy . && docker run -d -p 443:443 -e BACK_URI backend:12345 --name nginx-proxy nginx-proxy
2
+
1
3
FROM ghcr.io/devops-from-root/alpine:main
2
4
3
5
# Устанавливаем значения переменных
4
- ARG BACK_URI=localhost
5
- ENV BACK_URI=${BACK_URI}
6
+ ENV BACK_URI=localhost
6
7
7
8
# Устанавливаем необходимые пакеты
8
- RUN apk add --no-cache openssl netcat-openbsd nginx
9
+ RUN apk add --no-cache openssl curl netcat-openbsd nginx
9
10
10
11
# Создаем директорию для сертификатов
11
12
RUN mkdir -p /etc/nginx/ssl
12
13
13
14
# Генерируем самоподписанный сертификат
14
15
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"
15
16
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