netboot.xyz icon indicating copy to clipboard operation
netboot.xyz copied to clipboard

Fallback to the Internet if Images cant be found local

Open oe3gwu opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. No.

Describe the solution you'd like If I change "set live_endpoint" to a local endpoint, netboot shoot try to find the image. If the image isnt found locally, an automatically fallback to https://github.com/netbootxyz should happen. Currently the Boot Process fails.

Describe alternatives you've considered Download all the Images, thats nice but really not a solution for a Raspberry Pi Docker Container.

Additional context image

oe3gwu avatar Mar 21 '23 20:03 oe3gwu

I have managed to modify the nginx config to do this on my instance with the following settings

server {
        listen [NGINX_PORT];
        resolver 8.8.8.8;
        location / {
                root /assets;
                autoindex on;
                try_files $uri $uri/ @fallback;
        }
        location @fallback{
            rewrite  ^/(.*) /netbootxyz/$1 break;
            proxy_pass https://github.com;
            #proxy_redirect / /;
            proxy_intercept_errors on;
            error_page 301 302 307 = @handle_redirect;
        }
        location @handle_redirect {
            set $saved_redirect_location '$upstream_http_location';
            proxy_pass $saved_redirect_location;
        }
}

its not the best as its a combination of stuff from stackoverflow and some of my own config. the fallback is what redirects it to the github mirror if it cant find a file and the @handle_redirect is to hide the redirect from github.com to objects.githubusercontent.com. Ive not added caching to my config yet, but i will at somepoint to help with performance

miawgogo avatar Jan 24 '24 11:01 miawgogo

To add caching:

proxy_cache_path        /assets/cache keys_zone=fallback_cache:30720m levels=1:2 max_size=30720m inactive=30d;
proxy_buffer_size       128k;
proxy_buffers           4 256k;
proxy_busy_buffers_size 256k;

server {
        listen 80;
        resolver 8.8.8.8;
        location / {
                root /assets;
                autoindex on;
                try_files $uri $uri/ @fallback;
        }
        location @fallback {
            rewrite  ^/(.*) /netbootxyz/$1 break;
            proxy_cache_revalidate on;
            proxy_cache            fallback_cache;
            proxy_cache_valid      200 30d;
            proxy_cache_use_stale  error timeout invalid_header updating;
            proxy_pass             https://github.com;
            proxy_intercept_errors on;
            error_page 301 302 307 = @handle_redirect;
            add_header X-Netboot-Cache $upstream_cache_status;
        }
        location @handle_redirect {
            set $saved_redirect_location '$upstream_http_location';
            proxy_cache_revalidate on;
            proxy_cache            fallback_cache;
            proxy_cache_valid      200 30d;
            proxy_cache_use_stale  error timeout invalid_header updating;
            proxy_pass $saved_redirect_location;
            add_header X-Netboot-Cache $upstream_cache_status;
        }
}

grmrgecko avatar Mar 06 '24 16:03 grmrgecko