Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fallback to the Internet if Images cant be found local #1220

Open
oe3gwu opened this issue Mar 21, 2023 · 3 comments
Open

Fallback to the Internet if Images cant be found local #1220

oe3gwu opened this issue Mar 21, 2023 · 3 comments

Comments

@oe3gwu
Copy link

oe3gwu commented Mar 21, 2023

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

@miawgogo
Copy link

miawgogo commented Jan 24, 2024

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

@grmrgecko
Copy link

grmrgecko commented Mar 6, 2024

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;
        }
}

@gissf1
Copy link

gissf1 commented Nov 2, 2024

I skipped the caching for now on my system, but I think you can simplify the nginx config (or at least it worked for me) by doing this to simply redirect the client to the public live server:

server {
        listen 80;
        location / {
                root /assets;
                autoindex on;
                try_files $uri $uri/ @fallback;
        }
        location @fallback{
                return   307 https://github.com/netbootxyz$request_uri;
        }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants