feat(脚本): 修改v2ray gRPC nginx配置、优化tls安装判断、添加不使用gRPC的h2回落以加快网站的访问速度

pull/534/merge
mack-a 2021-06-17 15:23:34 +08:00
parent a21494305e
commit 47197484ca
1 changed files with 39 additions and 27 deletions

View File

@ -616,20 +616,20 @@ initTLSNginxConfig() {
updateRedirectNginxConf() { updateRedirectNginxConf() {
cat <<EOF >/etc/nginx/conf.d/alone.conf cat <<EOF >/etc/nginx/conf.d/alone.conf
server { server {
listen 80; listen 80;
listen [::]:80; listen [::]:80;
server_name ${domain}; server_name ${domain};
# shellcheck disable=SC2154 # shellcheck disable=SC2154
return 301 https://${domain}$request_uri; return 301 https://${domain}$request_uri;
} }
server { server {
listen 127.0.0.1:31300; listen 127.0.0.1:31300;
server_name _; server_name _;
return 403; return 403;
} }
EOF EOF
if [[ "${selectCoreType}" == "1" ]] && [[ -n $(echo ${selectCustomInstallType} | grep 5) || -z ${selectCustomInstallType} ]]; then if echo "${selectCustomInstallType}" |grep -q 5 || [[ -z "${selectCustomInstallType}" ]]; then
cat <<EOF >>/etc/nginx/conf.d/alone.conf cat <<EOF >>/etc/nginx/conf.d/alone.conf
server { server {
listen 127.0.0.1:31302 http2; listen 127.0.0.1:31302 http2;
@ -639,6 +639,17 @@ server {
grpc_pass grpc://127.0.0.1:31301; grpc_pass grpc://127.0.0.1:31301;
} }
} }
EOF
elif ! echo "${selectCustomInstallType}" |grep -q 4; then
cat <<EOF >>/etc/nginx/conf.d/alone.conf
server {
listen 127.0.0.1:31302 http2;
server_name ${domain};
root /usr/share/nginx/html;
location / {
}
}
EOF EOF
fi fi
@ -694,7 +705,7 @@ installTLS() {
echoContent skyBlue "\n进度 $1/${totalProgress} : 申请TLS证书\n" echoContent skyBlue "\n进度 $1/${totalProgress} : 申请TLS证书\n"
local tlsDomain=${domain} local tlsDomain=${domain}
# 安装tls # 安装tls
if [[ -f "/etc/v2ray-agent/tls/${tlsDomain}.crt" && -f "/etc/v2ray-agent/tls/${tlsDomain}.key" ]] || [[ -d "$HOME/.acme.sh/${tlsDomain}_ecc" && -f "$HOME/.acme.sh/${tlsDomain}_ecc/${tlsDomain}.key" && -f "$HOME/.acme.sh/${tlsDomain}_ecc/${tlsDomain}.cer" ]]; then if [[ -f "/etc/v2ray-agent/tls/${tlsDomain}.crt" && -f "/etc/v2ray-agent/tls/${tlsDomain}.key" && -n $(cat "/etc/v2ray-agent/tls/${tlsDomain}.crt") ]] || [[ -d "$HOME/.acme.sh/${tlsDomain}_ecc" && -f "$HOME/.acme.sh/${tlsDomain}_ecc/${tlsDomain}.key" && -f "$HOME/.acme.sh/${tlsDomain}_ecc/${tlsDomain}.cer" ]]; then
# 存在证书 # 存在证书
echoContent green " ---> 检测到证书" echoContent green " ---> 检测到证书"
checkTLStatus "${tlsDomain}" checkTLStatus "${tlsDomain}"
@ -705,7 +716,7 @@ installTLS() {
else else
echoContent green " ---> 证书有效" echoContent green " ---> 证书有效"
if ! ls /etc/v2ray-agent/tls/ | grep -q "${tlsDomain}.crt" || ! ls /etc/v2ray-agent/tls/ | grep -q "${tlsDomain}.key"; then if ! ls /etc/v2ray-agent/tls/ | grep -q "${tlsDomain}.crt" || ! ls /etc/v2ray-agent/tls/ | grep -q "${tlsDomain}.key" || [[ -z $(cat "/etc/v2ray-agent/tls/${tlsDomain}.crt") ]]; then
sudo "$HOME/.acme.sh/acme.sh" --installcert -d "${tlsDomain}" --fullchainpath "/etc/v2ray-agent/tls/${tlsDomain}.crt" --keypath "/etc/v2ray-agent/tls/${tlsDomain}.key" --ecc >/dev/null sudo "$HOME/.acme.sh/acme.sh" --installcert -d "${tlsDomain}" --fullchainpath "/etc/v2ray-agent/tls/${tlsDomain}.crt" --keypath "/etc/v2ray-agent/tls/${tlsDomain}.key" --ecc >/dev/null
else else
echoContent yellow " ---> 如未过期请选择[n]\n" echoContent yellow " ---> 如未过期请选择[n]\n"
@ -724,11 +735,12 @@ installTLS() {
sudo "$HOME/.acme.sh/acme.sh" --issue -d "${tlsDomain}" --standalone -k ec-256 >> /etc/v2ray-agent/tls/acme.log sudo "$HOME/.acme.sh/acme.sh" --issue -d "${tlsDomain}" --standalone -k ec-256 >> /etc/v2ray-agent/tls/acme.log
fi fi
sudo "$HOME/.acme.sh/acme.sh" --installcert -d "${tlsDomain}" --fullchainpath "/etc/v2ray-agent/tls/${tlsDomain}.crt" --keypath "/etc/v2ray-agent/tls/${tlsDomain}.key" --ecc >/dev/null if [[ -d "$HOME/.acme.sh/${tlsDomain}_ecc" && -f "$HOME/.acme.sh/${tlsDomain}_ecc/${tlsDomain}.key" && -f "$HOME/.acme.sh/${tlsDomain}_ecc/${tlsDomain}.cer" ]]; then
if [[ -z $(cat "/etc/v2ray-agent/tls/${tlsDomain}.crt") ]]; then sudo "$HOME/.acme.sh/acme.sh" --installcert -d "${tlsDomain}" --fullchainpath "/etc/v2ray-agent/tls/${tlsDomain}.crt" --keypath "/etc/v2ray-agent/tls/${tlsDomain}.key" --ecc >/dev/null
echoContent red " ---> TLS安装失败请检查acme日志" fi
exit 0
elif [[ -z $(cat "/etc/v2ray-agent/tls/${tlsDomain}.key") ]]; then if [[ ! -f "/etc/v2ray-agent/tls/${tlsDomain}.crt" || ! -f "/etc/v2ray-agent/tls/${tlsDomain}.key" ]] || [[ -z $(cat "/etc/v2ray-agent/tls/${tlsDomain}.key") || -z $(cat "/etc/v2ray-agent/tls/${tlsDomain}.crt") ]]; then
tail -n 10 /etc/v2ray-agent/tls/acme.log
echoContent red " ---> TLS安装失败请检查acme日志" echoContent red " ---> TLS安装失败请检查acme日志"
exit 0 exit 0
fi fi
@ -1574,7 +1586,7 @@ EOF
EOF EOF
# VLESS_TCP_TLS/XTLS # VLESS_TCP_TLS/XTLS
# 回落nginx # 回落nginx
local fallbacksList='{"dest":31300,"xver":0}' local fallbacksList='{"dest":31300,"xver":0},{"alpn":"h2","dest":31302,"xver":0}'
if echo "${selectCustomInstallType}" | grep -q 4 || [[ "$1" == "all" ]]; then if echo "${selectCustomInstallType}" | grep -q 4 || [[ "$1" == "all" ]]; then
# 回落trojan-go # 回落trojan-go
@ -1691,7 +1703,7 @@ EOF
fi fi
# VLESS gRPC # VLESS gRPC
if echo "${selectCustomInstallType}" | grep -q 5 || [[ "$1" == "all" ]]; then if echo "${selectCustomInstallType}" | grep -q 5 || [[ "$1" == "all" ]]; then
fallbacksList=${fallbacksList}',{"alpn":"h2","dest":31301,"xver":0}' # fallbacksList=${fallbacksList}',{"alpn":"h2","dest":31301,"xver":0}'
cat <<EOF >/etc/v2ray-agent/v2ray/conf/06_VLESS_gRPC_inbounds.json cat <<EOF >/etc/v2ray-agent/v2ray/conf/06_VLESS_gRPC_inbounds.json
{ {
"inbounds":[ "inbounds":[
@ -1809,7 +1821,7 @@ EOF
if echo "${selectCustomInstallType}" | grep -q 5 || [[ "$1" == "all" ]];then if echo "${selectCustomInstallType}" | grep -q 5 || [[ "$1" == "all" ]];then
echo >/dev/null echo >/dev/null
elif [[ -f "/etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json" ]];then elif [[ -f "/etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json" ]] && echo "${selectCustomInstallType}" | grep -q 4;then
# "h2", # "h2",
sed -i '/\"h2\",/d' $(grep "\"h2\"," -rl /etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json) sed -i '/\"h2\",/d' $(grep "\"h2\"," -rl /etc/v2ray-agent/v2ray/conf/02_VLESS_TCP_inbounds.json)
fi fi
@ -1925,7 +1937,7 @@ EOF
EOF EOF
# VLESS_TCP_TLS/XTLS # VLESS_TCP_TLS/XTLS
# 回落nginx # 回落nginx
local fallbacksList='{"dest":31300,"xver":0}' local fallbacksList='{"dest":31300,"xver":0},{"alpn":"h2","dest":31302,"xver":0}'
if echo "${selectCustomInstallType}" | grep -q 4 || [[ "$1" == "all" ]]; then if echo "${selectCustomInstallType}" | grep -q 4 || [[ "$1" == "all" ]]; then
# 回落trojan-go # 回落trojan-go
@ -2042,7 +2054,7 @@ EOF
fi fi
if echo "${selectCustomInstallType}" | grep -q 5 || [[ "$1" == "all" ]]; then if echo "${selectCustomInstallType}" | grep -q 5 || [[ "$1" == "all" ]]; then
fallbacksList=${fallbacksList}',{"alpn":"h2","dest":31302,"xver":0}' # fallbacksList=${fallbacksList}',{"alpn":"h2","dest":31302,"xver":0}'
cat <<EOF >/etc/v2ray-agent/xray/conf/06_VLESS_gRPC_inbounds.json cat <<EOF >/etc/v2ray-agent/xray/conf/06_VLESS_gRPC_inbounds.json
{ {
"inbounds":[ "inbounds":[
@ -2120,7 +2132,7 @@ EOF
EOF EOF
if echo "${selectCustomInstallType}" | grep -q 5 || [[ "$1" == "all" ]];then if echo "${selectCustomInstallType}" | grep -q 5 || [[ "$1" == "all" ]];then
echo >/dev/null echo >/dev/null
elif [[ -f "/etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json" ]];then elif [[ -f "/etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json" ]] && echo "${selectCustomInstallType}" | grep -q 4;then
# "h2", # "h2",
sed -i '/\"h2\",/d' $(grep "\"h2\"," -rl /etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json) sed -i '/\"h2\",/d' $(grep "\"h2\"," -rl /etc/v2ray-agent/xray/conf/02_VLESS_TCP_inbounds.json)
fi fi
@ -3897,7 +3909,7 @@ menu() {
cd "$HOME" || exit cd "$HOME" || exit
echoContent red "\n==============================================================" echoContent red "\n=============================================================="
echoContent green "作者mack-a" echoContent green "作者mack-a"
echoContent green "当前版本v2.5.2" echoContent green "当前版本v2.5.3"
echoContent green "Githubhttps://github.com/mack-a/v2ray-agent" echoContent green "Githubhttps://github.com/mack-a/v2ray-agent"
echoContent green "描述:八合一共存脚本\c" echoContent green "描述:八合一共存脚本\c"
showInstallStatus showInstallStatus