1.9 KiB
1.9 KiB
generating config with templates
configuration:
{%- import 'snip/cache.j2mod' as _cache -%}
{%- set my_caches = (j2cfg.my_caches or []) -%}
{%- for h in my_caches %}
{{ _cache.proxy_cache_path(h.name, size='10m', levels='1:2', inactive=h.max_time) }}
{%- endfor %}
server {
listen 8888;
location / { return 204; }
{%- for h in my_caches %}
location /{{ h.name }}/ {
proxy_pass {{ h.uri }}/;
proxy_cache {{ h.name }};
expires {{ h.valid_time }};
proxy_cache_valid 200 {{ h.valid_time }};
proxy_cache_valid any 30s;
}
{%- endfor %}
}
site configuration (via j2cfg/my-caches.yml
):
my_caches:
- name: apt_debian
uri: https://deb.debian.org/debian
valid_time: 180m
max_time: 1440h
- name: apt_debian_security
uri: https://deb.debian.org/debian-security
valid_time: 180m
max_time: 1440h
## and so on ...
docker-compose.yml:
version: "3.8"
services:
angie-conv-example-config-template:
container_name: angie-conv-example-config-template
image: docker.io/rockdrilla/angie-conv:v0.0.1
restart: always
privileged: true
stop_grace_period: 15s
network_mode: host
environment:
NGX_HTTP_TRANSPARENT_PROXY: 1
volumes:
- "./conf:/etc/angie:ro"
- "./data:/angie"
final configuration looks like this:
proxy_cache_path /run/ngx/cache/proxy_apt_debian
keys_zone=apt_debian:10m:file=/run/ngx/lib/proxy_apt_debian.keys
inactive=1440h
levels=1:2
;
# ...
server {
# ...
location /apt_debian/ {
proxy_pass https://deb.debian.org/debian/;
proxy_cache apt_debian;
expires 180m;
proxy_cache_valid 200 180m;
proxy_cache_valid any 30s;
}
# ...
}
Test URI e.g. with curl
:
curl -v http://localhost:8888/apt_debian/dists/bookworm/main/binary-all/Release