You can’t have a full url in the error_page (just uri)

Change:
 error_page 403 404 =200 
https://mybucket.s3.eu-west-2.amazonaws.com/sitedown.html;
   
to something like:

error_page 403 404 =200 /sitedown.html;

location /sitedown.html {
   proxy_pass https://mybucket.s3.eu-west-2.amazonaws.com;
}

(or you can do similar @named location with return 301 .. depending on if you 
want the client to be redirected to that particular bucket url).


Also you might need to enable recursive_error_pages 
http://nginx.org/en/docs/http/ngx_http_core_module.html#recursive_error_pages 
since you have  an error_page within error_page.

rr

From: Daniel Earle <d.e.ea...@gmail.com> 
Sent: piektdiena, 2022. gada 13. maijs 17:23
To: nginx@nginx.org
Subject: Trying to config for proxying to site down page

I'm trying to get nginx to forward to my S3 bucket when my web app k8 pod is 
down. So I was hoping the below config would, in the case of 50x error or no 
response, forward request to bucket, then if the document doesn't exist (very 
likely for first 50x request) - it would then return sitedown.html - this would 
then request some css files which would fail with same 50x then try on S3 and 
success.

However it just returns 404 when my application pod is down (if I remove  
proxy_intercept_errors on; error_page 403 404 =200 I get the S3 404 message as 
expected).

I want to avoid hosting the website down error page on the nginx server.

Below is my config (everything else config wise is as in the FROM 
nginxinc/nginx-unprivileged:1.21 docker image)

server {
    listen       8080 default_server;
    server_name  _;
    port_in_redirect off;
    client_max_body_size 51M;
    server_tokens off;

    error_page 501 502 503 504 = @holding_page_proxy;

    location @holding_page_proxy {
        proxy_pass 
https://tca-holding-pages-permits-dev.s3.eu-west-2.amazonaws.com;
        proxy_intercept_errors on;
        error_page 403 404 =200 
https://mybucket.s3.eu-west-2.amazonaws.com/sitedown.html;
    }

    location / {
          proxy_read_timeout 180s;
          proxy_set_header X-Real-IP  $http_x_real_ip;
          proxy_set_header X-Forwarded-Host "";
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
          proxy_next_upstream error timeout invalid_header http_502 http_503 
http_504 http_404;
          proxy_http_version 1.1;
          proxy_pass http://application:8080/;
    }

    # Deny access to the Spring Boot actuator.
    location /actuator {
        deny  all;
    }

    # probe for kubernetes checks
    location = /probe.html {
        root   /usr/share/nginx/html;
    }
}

_______________________________________________
nginx mailing list -- nginx@nginx.org
To unsubscribe send an email to nginx-le...@nginx.org

Reply via email to