From aa1eaccf5f3cfc45750a5bfb9b3b4242bb4e2031 Mon Sep 17 00:00:00 2001 From: schmelczerandras Date: Mon, 20 Jul 2020 15:53:10 +0200 Subject: [PATCH] Add 502 page for ingress --- ingress/Dockerfile | 15 ++++++- ingress/app.conf | 33 ---------------- ingress/nginx-config/nginx.conf | 70 +++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 34 deletions(-) delete mode 100644 ingress/app.conf create mode 100644 ingress/nginx-config/nginx.conf diff --git a/ingress/Dockerfile b/ingress/Dockerfile index 4bc4c14..b7c5192 100644 --- a/ingress/Dockerfile +++ b/ingress/Dockerfile @@ -1,3 +1,16 @@ +FROM error-pages as build-error-pages + +RUN python build.py 502 + + FROM nginx:alpine -COPY app.conf /etc/nginx/conf.d/ +WORKDIR /usr/share/nginx/html + +RUN rm -rf * + +COPY --from=build-error-pages /home/python/built errors +RUN find . -type f | xargs gzip -k9 &&\ + chmod -R 555 . + +COPY nginx-config /etc/nginx/ diff --git a/ingress/app.conf b/ingress/app.conf deleted file mode 100644 index bab1992..0000000 --- a/ingress/app.conf +++ /dev/null @@ -1,33 +0,0 @@ -server { - listen 80; - server_name decla.red; - server_tokens off; - - location /.well-known/acme-challenge/ { - root /var/www/certbot; - } - - location / { - return 301 https://$host$request_uri; - } -} - -server { - listen 443 ssl; - server_name decla.red; - server_tokens off; - - add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; - - ssl_certificate /etc/letsencrypt/live/decla.red/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/decla.red/privkey.pem; - include /etc/letsencrypt/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; - - location / { - proxy_pass http://frontend; - proxy_set_header Host $http_host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - } -} diff --git a/ingress/nginx-config/nginx.conf b/ingress/nginx-config/nginx.conf new file mode 100644 index 0000000..96ae6ad --- /dev/null +++ b/ingress/nginx-config/nginx.conf @@ -0,0 +1,70 @@ +user nginx; +worker_processes auto; + +error_log /var/log/nginx/error.log warn; +pid /var/run/nginx.pid; + +events { + worker_connections 1024; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + access_log /var/log/nginx/access.log main; + + keepalive_timeout 65; + + server { + listen 80; + server_name decla.red; + server_tokens off; + + location /.well-known/acme-challenge/ { + root /var/www/certbot; + } + + location / { + return 301 https://$host$request_uri; + } + } + + server { + listen 443 ssl; + server_name decla.red; + server_tokens off; + + add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; + + ssl_certificate /etc/letsencrypt/live/decla.red/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/decla.red/privkey.pem; + include /etc/letsencrypt/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; + + location ~ ^/(502).html$ { + root /usr/share/nginx/html/errors; + internal; + } + + location / { + proxy_pass http://frontend; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + location /bad { + proxy_pass http://backend; + proxy_set_header Host $http_host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + } + + error_page 502 /502.html; + } +}