109 lines
1.9 KiB
Markdown
109 lines
1.9 KiB
Markdown
# generating config with templates
|
|
|
|
configuration:
|
|
|
|
```nginx
|
|
{%- for h in (j2cfg.my_caches or []) %}
|
|
proxy_cache_path
|
|
/angie/my-cache/{{ h.name }}
|
|
keys_zone={{ h.name }}:20m
|
|
levels=1:2 inactive={{ h.max_time }};
|
|
{%- endfor %}
|
|
|
|
server {
|
|
listen 8888;
|
|
|
|
location / { return 204; }
|
|
|
|
{%- for h in (j2cfg.my_caches or []) %}
|
|
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`):
|
|
|
|
```yml
|
|
my_caches:
|
|
- name: proxy_apt_debian
|
|
uri: https://deb.debian.org/debian
|
|
valid_time: 180m
|
|
max_time: 1440h
|
|
- name: proxy_apt_debian_security
|
|
uri: https://deb.debian.org/debian-security
|
|
valid_time: 180m
|
|
max_time: 1440h
|
|
## and so on ...
|
|
```
|
|
|
|
---
|
|
|
|
docker-compose.yml:
|
|
|
|
```yml
|
|
version: "3.8"
|
|
|
|
services:
|
|
|
|
my-cache:
|
|
container_name: my-cache
|
|
image: docker.io/rockdrilla/angie-conv:v0.0.3
|
|
restart: always
|
|
privileged: true
|
|
stop_grace_period: 15s
|
|
network_mode: host
|
|
volumes:
|
|
- "./conf/image-entry:/image-entry:ro"
|
|
- "./conf/j2cfg:/angie/j2cfg:ro"
|
|
- "./conf/site:/angie/site:ro"
|
|
- "./cache:/angie/my-cache"
|
|
```
|
|
|
|
---
|
|
|
|
final configuration looks like this:
|
|
|
|
```nginx
|
|
proxy_cache_path
|
|
/angie/my-cache/proxy_apt_debian
|
|
keys_zone=proxy_apt_debian:20m
|
|
levels=1:2 inactive=1440h;
|
|
|
|
# ...
|
|
|
|
server {
|
|
# ...
|
|
|
|
location /proxy_apt_debian/ {
|
|
proxy_pass https://deb.debian.org/debian/;
|
|
|
|
proxy_cache proxy_apt_debian;
|
|
|
|
expires 180m;
|
|
|
|
proxy_cache_valid 200 180m;
|
|
proxy_cache_valid any 30s;
|
|
}
|
|
|
|
# ...
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
Test URI e.g. with `curl`:
|
|
```sh
|
|
curl -v http://localhost:8888/proxy_apt_debian/dists/bookworm/main/binary-all/Release
|
|
```
|