1
0

doc: add config-template example

This commit is contained in:
Konstantin Demin 2024-09-30 22:16:55 +03:00
parent d443811e1a
commit fd803b76e1
Signed by: krd
GPG Key ID: 4D56F87A8BA65FD0
8 changed files with 297 additions and 0 deletions

View File

@ -5,3 +5,4 @@
- [print env via NJS](njs/README.md)
- [print env via Perl](perl/README.md)
- [SSL with subdomains](ssl/README.md)
- [generating config with templates](config-template/README.md)

View File

@ -0,0 +1,113 @@
# 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
```

View File

@ -0,0 +1,13 @@
#!/bin/sh
unset d
d="${target_root}/cache/my-cache"
[ -d "$d" ] || install_userdir "$d"
unset p
while read -r p ; do
[ -n "$p" ] || continue
[ -d "$d/$p" ] || install_userdir "$d/$p"
done < /etc/angie/site.d/my-caches.txt
unset d p

View File

@ -0,0 +1,3 @@
#!/bin/sh
apt-install.sh angie-console-light
apt-clean.sh

View File

@ -0,0 +1,67 @@
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
- name: proxy_apt_postgresql
uri: https://apt.postgresql.org/pub/repos/apt
valid_time: 180m
max_time: 1440h
- name: proxy_apt_citus_debian
uri: https://repos.citusdata.com/community/debian
valid_time: 180m
max_time: 1440h
- name: proxy_apt_citus
uri: https://repos.citusdata.com/community
valid_time: 180m
max_time: 1440h
- name: proxy_apt_ubuntu
uri: https://mirror.yandex.ru/ubuntu
valid_time: 180m
max_time: 1440h
- name: proxy_apt_citus_ubuntu
uri: https://repos.citusdata.com/community/ubuntu
valid_time: 180m
max_time: 1440h
- name: proxy_apt_docker_ubuntu
uri: https://download.docker.com/linux/ubuntu
valid_time: 180m
max_time: 1440h
- name: proxy_go
uri: https://proxy.golang.org
valid_time: 120m
max_time: 1440h
- name: proxy_go_sum
uri: https://sum.golang.org
valid_time: 120m
max_time: 1440h
- name: proxy_go_dev
uri: https://go.dev
valid_time: 120m
max_time: 1440h
- name: proxy_npm
uri: https://registry.npmjs.org
valid_time: 120m
max_time: 1440h
- name: proxy_pypi
uri: https://pypi.org
valid_time: 120m
max_time: 1440h
- name: proxy_crates
uri: https://crates.io
valid_time: 120m
max_time: 1440h
- name: proxy_crates_index
uri: https://index.crates.io
valid_time: 120m
max_time: 1440h

View File

@ -0,0 +1,81 @@
map $uri
$to_proxy_uri
{
volatile;
~^/[^/]+/(.*)$ $1;
}
map $request_method
$to_proxy_method
{
default GET;
## already handled by "proxy_cache_convert_head on;" (default setting)
# HEAD GET;
OPTIONS OPTIONS;
}
## quirks
chunked_transfer_encoding off;
proxy_method $to_proxy_method;
proxy_ignore_client_abort on;
proxy_ignore_headers Cache-Control Expires Set-Cookie Vary X-Accel-Buffering X-Accel-Expires X-Accel-Limit-Rate;
## tuning
proxy_cache_key $to_proxy_uri$is_args$args;
proxy_cache_lock on;
proxy_cache_lock_age 20s;
proxy_cache_lock_timeout 25s;
proxy_cache_use_stale error timeout invalid_header updating http_429 http_500 http_502 http_503 http_504;
proxy_cache_revalidate on;
{%- 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; }
location /console/ {
# allow 127.0.0.0/8;
# deny all;
auto_redirect on;
alias /usr/share/angie-console-light/html/;
index index.html;
location /console/api/
{
access_log off;
api /status/;
}
location /console/api/config/
{
access_log off;
api /config/;
}
}
{%- 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 %}
}

View File

@ -0,0 +1,3 @@
{%- for h in (j2cfg.my_caches or []) %}
{{ h.name }}
{%- endfor %}

View File

@ -0,0 +1,16 @@
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"