doc: add config-template example
This commit is contained in:
parent
d443811e1a
commit
fd803b76e1
@ -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)
|
||||
|
113
doc/examples/config-template/README.md
Normal file
113
doc/examples/config-template/README.md
Normal 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
|
||||
```
|
13
doc/examples/config-template/conf/image-entry/80-my-caches.envsh
Executable file
13
doc/examples/config-template/conf/image-entry/80-my-caches.envsh
Executable 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
|
3
doc/examples/config-template/conf/image-entry/81-angie-console-light.sh
Executable file
3
doc/examples/config-template/conf/image-entry/81-angie-console-light.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
apt-install.sh angie-console-light
|
||||
apt-clean.sh
|
67
doc/examples/config-template/conf/j2cfg/my-caches.yml
Normal file
67
doc/examples/config-template/conf/j2cfg/my-caches.yml
Normal 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
|
81
doc/examples/config-template/conf/site/http-my-cache.conf.j2
Normal file
81
doc/examples/config-template/conf/site/http-my-cache.conf.j2
Normal 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 %}
|
||||
}
|
3
doc/examples/config-template/conf/site/my-caches.txt.j2
Normal file
3
doc/examples/config-template/conf/site/my-caches.txt.j2
Normal file
@ -0,0 +1,3 @@
|
||||
{%- for h in (j2cfg.my_caches or []) %}
|
||||
{{ h.name }}
|
||||
{%- endfor %}
|
16
doc/examples/config-template/docker-compose.yml
Normal file
16
doc/examples/config-template/docker-compose.yml
Normal 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"
|
Loading…
Reference in New Issue
Block a user