add caddy

This commit is contained in:
root
2022-05-26 17:58:02 +00:00
parent be6d2f94eb
commit aac1ca4df4
3 changed files with 34 additions and 5 deletions

16
Caddyfile Normal file
View File

@@ -0,0 +1,16 @@
http://:{$PORT} {
root * /root/html
file_server
reverse_proxy /h2 127.0.0.1:8082 {
transport http {
versions h2c
}
}
@websockets {
header Connection *Upgrade*
header Upgrade websocket
}
reverse_proxy @websockets localhost:8080
}

View File

@@ -1,12 +1,15 @@
FROM v2fly/v2fly-core:latest
RUN apk add nginx
RUN apk add caddy
RUN apk add gettext
RUN apk add curl
RUN apk add jq
COPY html /root/html/
COPY config.json.tp /root/
COPY nginx.template.conf /root/
# COPY caddy.template.conf /root/
COPY Caddyfile /root/
ADD startup.sh /startup.sh
RUN chmod +x /startup.sh

16
startup.sh Normal file → Executable file
View File

@@ -1,16 +1,26 @@
#!/bin/sh
envsubst < /root/config.json.tp > /root/config.json
envsubst '\$PORT' < /root/nginx.template.conf > /root/nginx.conf
# envsubst '\$PORT' < /root/nginx.template.conf > /root/nginx.conf
# get random page from wikipedia
if [[ -e "/root/html/index.html" ]]; then
echo "index.html exsit, skip genreate index page"
else
randomurl=$(curl -L 'https://en.wikipedia.org/api/rest_v1/page/random/summary' | jq -r '.content_urls.desktop.page')
echo $randomurl
curl "$randomurl" -o /root/html/index.html
fi
# Run V2Ray
if [[ $TUNNEL_TOKEN ]]; then
echo 'has tunnel token, run cloudflared tunnel'
wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -O /root/cloudflared
chmod +x /root/cloudflared
/usr/bin/v2ray -config /root/config.json & /root/cloudflared tunnel --no-autoupdate run --token $TUNNEL_TOKEN & nginx -c /root/nginx.conf -g 'daemon off;'
# /usr/bin/v2ray -config /root/config.json & /root/cloudflared tunnel --no-autoupdate run --token $TUNNEL_TOKEN & nginx -c /root/nginx.conf -g 'daemon off;'
/usr/bin/v2ray -config /root/config.json & /root/cloudflared tunnel --no-autoupdate run --token $TUNNEL_TOKEN & caddy start --config /root/Caddyfile
else
/usr/bin/v2ray -config /root/config.json & nginx -c /root/nginx.conf -g 'daemon off;'
caddy start --config /root/Caddyfile
/usr/bin/v2ray -config /root/config.json
fi