114 lines
2.0 KiB
Markdown
114 lines
2.0 KiB
Markdown
|
# generating config with templates
|
||
|
|
||
|
configuration:
|
||
|
|
||
|
```nginx
|
||
|
map $uri $to_proxy_uri
|
||
|
{
|
||
|
~^/[^/]+/(.*)$ $1;
|
||
|
}
|
||
|
|
||
|
{%- 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 }}/$to_proxy_uri$is_args$args;
|
||
|
|
||
|
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.2
|
||
|
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/$to_proxy_uri$is_args$args;
|
||
|
|
||
|
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
|
||
|
```
|