Fixing My Local Nginx Cache Setup for Flatpaks

I followed this guide to set up a local Nginx cache server for Flathub. Everything was functioning well for nearly a year, but it has recently stopped working. Below is my Nginx configuration:

map $status $cache_header {
    200     "public";
    302     "public";
    default "no-cache";
}

server {
    listen 0.0.0.0:8080; # you may want to listen on port 80, or add TLS
    server_name my-cache.local; # replace this with your hostname, or system IP

    # flathub cache
    set $flathub_cache https://dl.flathub.org;

    location /flathub/ {
        rewrite  ^/flathub/(.*) /$1 break;
        resolver my-dns.local ipv6=off; # I use my local DNS, but feel free to use whatever you prefer.
        proxy_cache flathub;
        proxy_cache_key     "$request_filename";
        add_header Cache-Control $cache_header always;
        proxy_cache_valid   200 302     300d;
        expires max;
        proxy_pass  $flathub_cache;
    }
}

proxy_cache_path    /var/cache/nginx/flathub/cache levels=1:2
    keys_zone=flathub:5m
    max_size=20g
    inactive=60d
    use_temp_path=off;

I initially had to add resolver my-dns.local ipv6=off; for it to function correctly.

However, I’m now encountering the error: error: Unable to load summary from remote flathub: Server returned status 421 when trying to install Flatpaks, and I receive F: Warning: Treating remote fetch error as non-fatal ... when running flatpak update.
To update and install Flatpaks, I need to use set $flathub_cache http://dl.flathub.org; instead of set $flathub_cache https://dl.flathub.org;, but as I understand it, this results in a redirection to https on Flathub’s servers, which prevents any caching from occurring. If I bypass the local cache server, Flatpaks installs and updates as expected.

Does anyone have any suggestions on how to resolve this issue?

To anyone interested in using this on a local server, it is now working again as it was. There must have been a change on Flathub’s side. Thank you to whoever made that happen!

This topic was automatically closed after 11 hours. New replies are no longer allowed.