diff --git a/ansible/roles/nginx_proxy/tasks/main.yml b/ansible/roles/nginx_proxy/tasks/main.yml index ec44e69..ebe481d 100644 --- a/ansible/roles/nginx_proxy/tasks/main.yml +++ b/ansible/roles/nginx_proxy/tasks/main.yml @@ -9,6 +9,20 @@ enabled: yes state: started +- name: Create directory for error pages + file: + path: /var/www/errors + state: directory + owner: nginx + group: nginx + mode: '0755' + +- name: Deploy custom error page + template: + src: site_down.html.j2 + dest: /var/www/errors/site_down.html + mode: '0644' + - name: Deploy Proxy Configuration template: src: proxy.conf.j2 @@ -17,4 +31,4 @@ - name: Reload Nginx systemd: name: nginx - state: reloaded \ No newline at end of file + state: reloaded diff --git a/ansible/roles/nginx_proxy/templates/proxy.conf.j2 b/ansible/roles/nginx_proxy/templates/proxy.conf.j2 index 4572c22..1de783b 100644 --- a/ansible/roles/nginx_proxy/templates/proxy.conf.j2 +++ b/ansible/roles/nginx_proxy/templates/proxy.conf.j2 @@ -1,6 +1,6 @@ upstream backend { {% for server in upstream_servers %} - server {{ server }} max_fails=1 fail_timeout=1s; + server {{ server }} max_fails=1 fail_timeout=5s; {% endfor %} } @@ -12,12 +12,20 @@ server { ssl_certificate /etc/nginx/ssl/{{ ssl_cert_file }}; ssl_certificate_key /etc/nginx/ssl/{{ ssl_key_file }}; + error_page 502 503 504 /custom_50x.html; + + location = /custom_50x.html { + root /var/www/errors; + internal; + } + location / { proxy_pass http://backend; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504; + proxy_intercept_errors on; } location /health { @@ -26,4 +34,4 @@ server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } -} +} \ No newline at end of file diff --git a/ansible/roles/nginx_proxy/templates/site_down.html.j2 b/ansible/roles/nginx_proxy/templates/site_down.html.j2 new file mode 100644 index 0000000..efcae73 --- /dev/null +++ b/ansible/roles/nginx_proxy/templates/site_down.html.j2 @@ -0,0 +1,35 @@ + + +
+ +