Skip to content

Instantly share code, notes, and snippets.

@Duncaen
Last active September 27, 2023 15:48
Show Gist options
  • Save Duncaen/645f119544a65ad0fd32e0e0400e22a3 to your computer and use it in GitHub Desktop.
Save Duncaen/645f119544a65ad0fd32e0e0400e22a3 to your computer and use it in GitHub Desktop.
voidlinux nginx caching repository proxy
proxy_cache_path /repo_cache use_temp_path=off keys_zone=repo_cache:5m max_size=20g inactive=7d;
server {
server_name _;
listen 80;
proxy_cache repo_cache;
# if the backend is not reachable use cache
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
# wait 5s to finish privious requests to the backend and try to use the cache
proxy_cache_lock on;
proxy_cache_lock_age 5s;
proxy_cache_lock_timeout 5s;
# timeouts if the backend is not reachable
proxy_connect_timeout 30s;
proxy_read_timeout 30s;
proxy_send_timeout 30s;
# ignore if the client aborts, to still fill the cache with the requested file
#proxy_ignore_client_abort on;
location / {
proxy_cache_revalidate on;
proxy_cache_valid 200 1m;
add_header X-Cache-Status $upstream_cache_status;
add_header X-Mirror repo-fi.voidlinux.org;
proxy_pass https://repo-fi.voidlinux.org;
}
location ~ /(distfiles|live|logos|static) {
# stuff that can be cached for longer periods
proxy_cache_revalidate off;
proxy_cache_valid 200 7d;
add_header X-Cache-Status $upstream_cache_status;
add_header X-Mirror repo-fi.voidlinux.org;
proxy_pass https://repo-fi.voidlinux.org;
}
location ~ \.xbps$ {
proxy_cache_revalidate off;
proxy_cache_valid 200 7d;
add_header X-Cache-Status $upstream_cache_status;
add_header X-Mirror repo-fi.voidlinux.org;
proxy_pass https://repo-fi.voidlinux.org;
}
location ~ /(void-updates|xlocate) {
# this is updated daily, maybe increase cache time
proxy_cache_revalidate off;
proxy_cache_valid 200 10m;
add_header X-Cache-Status $upstream_cache_status;
add_header X-Mirror repo-fi.voidlinux.org;
proxy_pass https://repo-fi.voidlinux.org;
}
}
@Duncaen
Copy link
Author

Duncaen commented Sep 30, 2022

X-Mirror is a header sent to the client to show which mirror was used, the idea behind this was if you use multiple upstream mirrors this would help to debug issues. Sending that header from a client does nothing.

I think you would have to rewrite the request to include the target folder or use the same structure to make it work with different folder structures.

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