support fallback website

This commit is contained in:
root
2022-05-22 08:21:04 +00:00
parent 251a7f9e8e
commit 567845db7a
7 changed files with 146 additions and 51 deletions

View File

@@ -1,7 +1,13 @@
FROM v2fly/v2fly-core:latest
RUN wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -O /root/cloudflared
RUN chmod +x /root/cloudflared
RUN apk add nginx
RUN apk add gettext
COPY html /root/html/
COPY config.json.tp /root/
COPY nginx.template.conf /root/
ADD startup.sh /startup.sh
RUN chmod +x /startup.sh

48
config.json.tp Normal file
View File

@@ -0,0 +1,48 @@
{
"policy": {
"levels": {
"0": {
"handshake": 5,
"connIdle": 300,
"uplinkOnly": 2,
"downlinkOnly": 5,
"statsUserUplink": false,
"statsUserDownlink": false,
"bufferSize": 10240
}
},
"system": {
"statsInboundUplink": false,
"statsInboundDownlink": false,
"statsOutboundUplink": false,
"statsOutboundDownlink": false
}
},
"inbounds": [
{
"port": 8080,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "$UUID",
"level": 0
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "none",
"wsSettings": {
"path": "/v2ws"
}
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
]
}

12
html/50x.html Normal file
View File

@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>500</title>
</head>
<body>
500
</body>
</html>

13
html/index.html Normal file
View File

@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./test.js"></script>
</head>
<body>
My first website
</body>
</html>

1
html/test.js Normal file
View File

@@ -0,0 +1 @@
alert("test alert")

57
nginx.template.conf Normal file
View File

@@ -0,0 +1,57 @@
user root;
worker_processes 4; # Heroku dynos have at least four cores.
error_log stderr;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
access_log /dev/stdout;
server_tokens off; # Hide nginx version in Server header & page footers
# include /etc/nginx/conf.d/*.conf;
server {
listen $PORT;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
# 用来proxy https nginx 暂时不支持proxy pass http2.0, 但是可以用SIN 来route
# location /dash/ {
# proxy_pass https://dash.zizi.press:4000/;
# }
location / {
root /root/html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /root/html;
}
location /v2ws { # 与 V2Ray 配置中的 path 保持一致
if ($http_upgrade != "websocket") { # WebSocket协商失败时返回404
return 404;
}
proxy_redirect off;
proxy_pass http://127.0.0.1:8080; # 假设WebSocket监听在环回地址的10000端口上
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
# Show real IP in v2ray access.log
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}

View File

@@ -1,58 +1,16 @@
#!/bin/sh
cat << EOF > /etc/v2ray/config.json
{
"policy": {
"levels": {
"0": {
"handshake": 5,
"connIdle": 300,
"uplinkOnly": 2,
"downlinkOnly": 5,
"statsUserUplink": false,
"statsUserDownlink": false,
"bufferSize": 10240
}
},
"system": {
"statsInboundUplink": false,
"statsInboundDownlink": false,
"statsOutboundUplink": false,
"statsOutboundDownlink": false
}
},
"inbounds": [
{
"port": $PORT,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "$UUID",
"level": 0
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"security": "none"
}
}
],
"outbounds": [
{
"protocol": "freedom"
}
]
}
EOF
envsubst < /root/config.json.tp > /root/config.json
envsubst '\$PORT' < /root/nginx.template.conf > /root/nginx.conf
# Run V2Ray
if [[ $TUNNEL_TOKEN ]]; then
echo 'has tunnel token, run cloudflared tunnel'
/usr/bin/v2ray -config /etc/v2ray/config.json & /root/cloudflared tunnel --no-autoupdate run --token $TUNNEL_TOKEN
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;'
else
/usr/bin/v2ray -config /etc/v2ray/config.json
/usr/bin/v2ray -config /root/config.json & nginx -c /root/nginx.conf -g 'daemon off;'
fi