forked from the-hidden-eye/docker-caching-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·106 lines (83 loc) · 4.23 KB
/
entrypoint.sh
File metadata and controls
executable file
·106 lines (83 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
#set -euo pipefail
INTPORT=65533
echo "${UPSTREAM_PROTO}"|grep -q ^$ && UPSTREAM_PROTO="https"
while (true);do
redis-server /etc/redis.conf ;sleep 3
done &
cat /rp.yaml |tee /rp2.yaml >> /rp1.yaml
sed 's/65533/65534/g' -i /rp2.yaml
(mkdir -p /var/run/redis/ ;chmod ugo+rwx /var/run/redis/ ) &
sed -i "s|\$MAX_SIZE|"${MAX_SIZE:-10g}"|" /etc/nginx/nginx.conf
REALUPSTREAM=$(echo "${UPSTREAM}"|sed 's~https://~~g;s~http://~~g'|sed 's/\/.\+//g')
#sed -i "s|MYUPSTREAM|"${REALUPSTREAM}"|g" /etc/nginx/nginx.conf
sed -i "s|MYUPSTREAM|127.0.0.1|g" /etc/nginx/nginx.conf
sed -i 's~proxy_redirect default;~proxy_redirect default;\nproxy_redirect http://127.0.0.1:'${INTPORT}'/ $scheme$http_host/;\nproxy_redirect '${UPSTREAM_PROTO}'://'${REALUPSTREAM}'/ $scheme$http_host/;~g' /etc/nginx/nginx.conf
sed -i "s|MYPORT|"${INTPORT}"|g" /etc/nginx/nginx.conf
echo '- address: '${UPSTREAM_PROTO}"://"${REALUPSTREAM}'
weight: 2'|tee -a /rp2.yaml /rp1.yaml
#socat "TCP-LISTEN:${INTPORT},fork,reuseaddr,bind=127.0.0.1" "OPENSSL-CONNECT:${REALUPSTREAM}:443,verify=0" &
#sed 's/#morezones/#morezones\n private-domain: "'${REALUPSTREAM}'"\n local-data: "'${REALUPSTREAM}'. A 127.0.0.1"/g' -i /etc/unbound.conf
sed -i "s|\$GZIP|"${GZIP:-on}"|" /etc/nginx/nginx.conf
sed -i "s|\$ALLOWED_ORIGIN|"${ALLOWED_ORIGIN:-*}"|" /etc/nginx/nginx.conf
sed -i "s|\$PROXY_READ_TIMEOUT|"${PROXY_READ_TIMEOUT:-120s}"|" /etc/nginx/nginx.conf
sed -i "s|\$MAX_INACTIVE|"${MAX_INACTIVE:-60m}"|" /etc/nginx/nginx.conf
sed -i "s|UPSTREAM_PROTO|"${UPSTREAM_PROTO}"|" /etc/nginx/nginx.conf
INTPORT=$(expr ${INTPORT} + 1)
sed -i 's|#more_backends|#more_backends\n server 127.0.0.1:'${INTPORT}" max_fails=2 fail_timeout=5s;|g" /etc/nginx/nginx.conf
sed -i 's~proxy_redirect default;~proxy_redirect default;\nproxy_redirect http://127.0.0.1:'${INTPORT}'/ $scheme$http_host/;~g' /etc/nginx/nginx.conf
echo "${MORE_UPSTREAMS}"|sed 's/|/\n/g'|while read addsrv;do
INTPORT=$(expr ${INTPORT} + 1)
REALSRV=$(echo "${addsrv}"|sed 's~https://~~g;s~http://~~g'|sed 's/\/.\+//g')
# sed -i 's|#more_backends|#more_backends\n server '${REALSRV}':'${INTPORT}" max_fails=2 fail_timeout=5s;|g" /etc/nginx/nginx.conf
#sed 's/#morezones/#morezones\n private-domain: "'${REALSRV}'"\n local-zone: "'${REALSRV}'." redirect\n local-data: "'${REALSRV}'. A 127.0.0.1"/g' -i /etc/unbound.conf
#socat "TCP-LISTEN:${INTPORT},fork,reuseaddr,bind=127.0.0.1" "OPENSSL-CONNECT:${REALSRV}:443,verify=0" &
sed -i 's~proxy_redirect default;~proxy_redirect default;\nproxy_redirect '${UPSTREAM_PROTO}'://'${REALSRV}'/ $scheme$http_host/;~g' /etc/nginx/nginx.conf
echo '- address: '${UPSTREAM_PROTO}"://"${REALSRV}'
weight: 2'|tee -a /rp2.yaml /rp1.yaml
done
#[[ -z "$PORT" ]] || sed -i "s|listen 80|listen "$PORT"|" /etc/nginx/nginx.conf
NGXPORT=8000
sed -i "s|listen 80|listen "$NGXPORT"|" /etc/nginx/nginx.conf
timeout 10 curl -6 https://www.google.com -o /dev/null && (
sed 's/ipv6=off//g' -i /etc/nginx/nginx.conf
sed 's~private-address: ::/0~#private-address: ::/0~g' /etc/unbound.conf
)
if [[ "${PROXY_CACHE_VALID+x}" ]]; then
PROXY_CACHE_VALID="proxy_cache_valid ${PROXY_CACHE_VALID};"
else
PROXY_CACHE_VALID="proxy_cache_valid 3h"
fi
cat /etc/unbound.conf |nl
sed -i "s|\$PROXY_CACHE_VALID|${PROXY_CACHE_VALID-}|" /etc/nginx/nginx.conf
nginx -t || nginx -T
nginx -t || exit 1
unbound -dd -c /etc/unbound.conf &
sleep 1
nslookup $REALUPSTREAM 127.0.0.1
#nginx -T |grep listen
nginx -T|grep -e server -e proxy_redirect
sleep 3;
cat /rp1.yaml;sleep 0.5
while (true);do
/usr/local/bin/rp --config /rp1.yaml serve ;sleep 3
done &
cat /rp2.yaml
while (true);do
/usr/local/bin/rp --config /rp2.yaml serve ;sleep 3
done &
export UPSTREAM_URL="http://127.0.0.1:$NGXPORT"
export LOG_LEVEL=info
#verbosity: trace, debug, info, warn, error, fatal, panic (default info)
export ATTEMPT_HTTP2=false
export TTL=2160m
export FRONTEND_URL=":"${PORT}
#export BACKEND_URL=redis://var/run/redis/redis.sock
#export BACKEND_URL=redis-socket://var/run/redis/redis.sock
export BACKEND_URL=redis://127.0.0.1:6379
ls -lh1 /usr/bin/cache-proxy
while (true);do
/usr/bin/cache-proxy 2>&1 |grep -v -e "HIT GET.*/healthcheck (200)" ;sleep 3
done &
#exec "$@"
ash /nginx.sh