upstream ubuntu {
# choose your nearest mirror
server de.archive.ubuntu.com;
server uk.archive.ubuntu.com;
server us.archive.ubuntu.com;
server archive.ubuntu.com backup;
}
tcp_nopush on;
tcp_nodelay on;
types_hash_max_size 2048;
# where the cache is located on disk
# to keep the data persistent, make it a docker volume
proxy_cache_path /var/repo_mirror # defines where the cache is stashed
# defines cache path heirarchy
levels=1:2
# defines name and size of zone where all cache keys and cache metadata are stashed.
keys_zone=repository_cache:50m
# data access timeout - don't cache packages for more than two weeks
inactive=14d
# Cache size limit
max_size=10g;
server {
listen 80;
root /var/www/;
# some additional ISO files on the mirror, added via docker volume
location /cdimages/ {
autoindex on;
}
# don't log in production mode, way too much info
access_log off;
# Location directive for the /ubuntu path
location /ubuntu {
# cache root, see above
root /var/repo_mirror/index_data;
# look for files in the following order
try_files $uri @ubuntu;
}
# directive for the location defined above
location @ubuntu {
# map to upstream
proxy_pass http://ubuntu;
# two weeks of caching for http code 200 response content
# 15 minutes for 301 and 302
# one minute for everything else
proxy_cache_valid 200 14d;
proxy_cache_valid 301 302 15m;
proxy_cache_valid any 1m;
# set "repository_cache" zone defined above
proxy_cache repository_cache;
# Use stale data in those error events
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
# go to backup server those error events
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
# lock parallel requests and fetch from backend only once
proxy_cache_lock on;
# set some debug headers, just in case
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded_For $proxy_add_x_forwarded_for;
add_header X-Mirror-Upstream-Status $upstream_status;
add_header X-Mirror-Upstream-Response-Time $upstream_response_time;
add_header X-Mirror-Status $upstream_cache_status;
}
}