0

Is it possible to setup nginx to reverse proxy to a server, but if the file doens't exist on server A to then have a fallback to server B where the file definitely will be.

I need to do a 2TB S3 migration and it would simplify the process if nginx could be setup this way.

Here is what I'm using as a reverse proxy config currently:

http {
    proxy_cache_path  /data/nginx/cache  levels=1:2    keys_zone=STATIC:100m
    inactive=30d  max_size=10g;
    server {
        location /image/ {
            proxy_pass             https://origin.example.com/;
            proxy_set_header    Host    origin.example.com;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            proxy_cache            STATIC;
            proxy_cache_valid      200  30d;
            proxy_cache_use_stale  error timeout invalid_header updating
            http_500 http_502 http_503 http_504;
        }

1 Answer 1

0

Nginx Plus has Active Health Check capability. You can add the 2 servers to an upstream group, apply an active health check in respect of the URI for the file, and if a 404 error is returned, Nginx will mark that server as unhealthy, and all requests will flow to the other server in the group.

https://docs.nginx.com/nginx/admin-guide/load-balancer/http-health-check/#hc_active

However, that will bounce all your traffic to the other server.

If you have control of the upstream, you could also use X-Accel:

https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/

If the file did not exist on the upstream, the upstream would return the X-Accel-Redirect header, which the reverse proxy would read, and request the file from the other server.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .