From 83403e306cc3e36a49612f2e43795c89286e8572 Mon Sep 17 00:00:00 2001 From: paniy Date: Wed, 7 Apr 2021 10:44:06 +0800 Subject: [PATCH] Easily modify Nginx upstream server --- README.md | 2 +- install.sh | 70 ++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 5dd03aa..7b2a7d9 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,6 @@ Xray 服务端配置:`/etc/xray/config.json` Nginx 目录: `/etc/nginx` -证书文件:`/etc/idleleo/cert/xray.key 和 /etc/idleleo/cert/xray.crt` 请注意证书权限设置 +证书文件:`/etc/idleleo/cert/xray.key` 和 `/etc/idleleo/cert/xray.crt` 请注意证书权限设置 配置信息文件等:`/etc/idleleo` diff --git a/install.sh b/install.sh index 87f4504..5b2c46b 100644 --- a/install.sh +++ b/install.sh @@ -33,7 +33,7 @@ Error="${Red}[错误]${Font}" Warning="${Red}[警告]${Font}" # 版本 -shell_version="1.5.2.8" +shell_version="1.5.3.0" shell_mode="None" shell_mode_show="未安装" version_cmp="/tmp/version_cmp.tmp" @@ -41,6 +41,7 @@ xray_conf_dir="/usr/local/etc/xray" nginx_conf_dir="/etc/nginx/conf/conf.d" xray_conf="${xray_conf_dir}/config.json" nginx_conf="${nginx_conf_dir}/xray.conf" +nginx_upstream_conf="${nginx_conf_dir}/xray-server.conf" idleleo_xray_dir="/etc/idleleo" idleleo_commend_file="/usr/bin/idleleo" ssl_chainpath="${idleleo_xray_dir}/cert" @@ -309,12 +310,6 @@ UUIDv5_tranc() { echo "import uuid;UUID_NAMESPACE=uuid.UUID('00000000-0000-0000-0000-000000000000');print(uuid.uuid5(UUID_NAMESPACE,'$1'));" | python3 } -stop_service() { - systemctl stop nginx - systemctl stop xray - echo -e "${OK} ${GreenBG} 停止已有服务 ${Font}" -} - modify_alterid() { echo -e "${Warning} ${YellowBG} VLESS 不需要 alterid ${Font}" } @@ -350,7 +345,7 @@ modify_nginx_port() { port="$(info_extraction '\"port\"')" fi sed -i "/ssl http2;$/c \\\t\\tlisten ${port} ssl http2;" ${nginx_conf} - sed -i "8c \\\t\\tlisten [::]:${port} ssl http2;" ${nginx_conf} + sed -i "5c \\\t\\tlisten [::]:${port} ssl http2;" ${nginx_conf} judge "Xray port 修改" [ -f ${xray_qr_config_file} ] && sed -i "/\"port\"/c \\ \"port\": \"${port}\"," ${xray_qr_config_file} echo -e "${OK} ${GreenBG} 端口号: ${port} ${Font}" @@ -360,7 +355,7 @@ modify_nginx_other() { sed -i "/server_name/c \\\t\\tserver_name ${domain};" ${nginx_conf} if [[ "$shell_mode" != "xtls" ]]; then sed -i "/location/c \\\tlocation ${camouflage}" ${nginx_conf} - sed -i "/xray-serverc/c \\\t\\t\\tserver 127.0.0.1:${xport} weight=2 max_fails=10 fail_timeout=1;" ${nginx_conf} + sed -i "/xray-serverc/c \\\t\\t\\tserver 127.0.0.1:${xport} weight=50 max_fails=5 fail_timeout=2;" ${nginx_upstream_conf} fi sed -i "/return/c \\\t\\treturn 301 https://${domain}\$request_uri;" ${nginx_conf} sed -i "/returc/c \\\t\\t\\treturn 302 https://www.idleleo.com/helloworld;" ${nginx_conf} @@ -371,6 +366,27 @@ modify_nginx_other() { #sed -i "27i \\\tproxy_intercept_errors on;" ${nginx_dir}/conf/nginx.conf } +modify_nginx_upstream_server() { + if [[ "$shell_mode" == "ws" ]]; then + echo -e "${GreenBG} 是否追加 Nginx 负载均衡 [Y/N]? ${Font}" + echo -e "${Warning} ${YellowBG} 如不清楚具体用途, 请勿继续! ${Font}" + read -r modify_nginx_upstream_server_fq + case $modify_nginx_upstream_server_fq in + [yY][eE][sS] | [yY]) + read -rp "请输入负载均衡 地址 (host):" upstream_host + read -rp "请输入负载均衡 端口 (port):" upstream_port + read -rp "请输入负载均衡 权重 (0~100, 初始值为50):" upstream_weight + sed -i "1a\server ${upstream_host}:${upstream_port} weight=${upstream_weight} max_fails=5 fail_timeout=2;" ${nginx_upstream_conf} + systemctl restart nginx + judge "追加 Nginx 负载均衡" + ;; + *) ;; + esac + else + echo -e "${Error} ${RedBG} 当前模式不支持此操作 ${Font}" + fi +} + modify_path() { sed -i "/\"path\"/c \ \"path\":\"${camouflage}\"" ${xray_conf} if [[ "$shell_mode" != "xtls" ]] || [[ "$xtls_add_ws" == "on" ]]; then @@ -757,9 +773,7 @@ nginx_conf_add() { cat >${nginx_conf_dir}/xray.conf <${nginx_conf_dir}/xray-server.conf <