Skip to content

Commit

Permalink
Add nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
loyess committed Nov 18, 2019
1 parent 83d0c6e commit 4f96f7a
Show file tree
Hide file tree
Showing 9 changed files with 353 additions and 22 deletions.
1 change: 1 addition & 0 deletions format_converter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ dos2unix ./prepare/cloak_prepare.sh

dos2unix ./tools/shadowsocks_install.sh
dos2unix ./tools/caddy_install.sh
dos2unix ./tools/nginx_install.sh



Expand Down
104 changes: 96 additions & 8 deletions prepare/v2ray_plugin_prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,82 @@ transport_mode_menu(){
done
}

web_server_menu(){
local libev_v2ray=$1
local WEB_SERVER_STYLE=(caddy nginx)
if [[ ${libev_v2ray} = "4" || ${libev_v2ray} = "5" ]]; then
while true
do
echo -e "请选择一个web服务器\n"
for ((i=1;i<=${#WEB_SERVER_STYLE[@]};i++)); do
hint="${WEB_SERVER_STYLE[$i-1]}"
echo -e "${Green} ${i}.${suffix} ${hint}"
done
echo
read -e -p "(默认:${WEB_SERVER_STYLE[0]}):" web_flag
[ -z "$web_flag" ] && web_flag=1
expr ${web_flag} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo
echo -e "${Error} 请输入一个数字"
echo
continue
fi
if [[ "$web_flag" -lt 1 || "$web_flag" -gt ${#WEB_SERVER_STYLE[@]} ]]; then
echo
echo -e "${Error} 请输入一个数字在 [1-${#WEB_SERVER_STYLE[@]}] 之间"
echo
continue
fi

web_server=${WEB_SERVER_STYLE[$web_flag-1]}
echo
echo -e "${Red} web = ${web_server}${suffix}"
echo

break
done
fi
}

choose_nginx_version_menu(){
local web_flag=$1
local NGINX_PACKAGES_V=(Stable Mainline)

if [[ ${web_flag} = "2" ]]; then
while true
do
echo -e "请选择Nginx软件包版本\n"
for ((i=1;i<=${#NGINX_PACKAGES_V[@]};i++)); do
hint="${NGINX_PACKAGES_V[$i-1]}"
echo -e "${Green} ${i}.${suffix} ${hint}"
done
echo
read -e -p "(默认:${NGINX_PACKAGES_V[0]}):" pkg_flag
[ -z "$pkg_flag" ] && pkg_flag=1
expr ${pkg_flag} + 1 &>/dev/null
if [ $? -ne 0 ]; then
echo
echo -e "${Error} 请输入一个数字"
echo
continue
fi
if [[ "$pkg_flag" -lt 1 || "$pkg_flag" -gt ${#NGINX_PACKAGES_V[@]} ]]; then
echo
echo -e "${Error} 请输入一个数字在 [1-${#NGINX_PACKAGES_V[@]}] 之间"
echo
continue
fi

echo
echo -e "${Red} version = ${NGINX_PACKAGES_V[$pkg_flag-1]}${suffix}"
echo

break
done
fi
}

v2ray_plugin_prot_reset(){
shadowsocksport=$1
echo
Expand Down Expand Up @@ -296,9 +372,11 @@ error_info_text(){
install_prepare_libev_v2ray(){
error_info_text
transport_mode_menu
web_server_menu ${libev_v2ray}
choose_nginx_version_menu ${web_flag}


if [[ ${libev_v2ray} == "1" ]]; then
if [[ ${libev_v2ray} = "1" ]]; then
if check_port_occupy "80"; then
echo -e "${Error} 检测到80端口被占用,请排查后重新运行." && exit 1
fi
Expand All @@ -307,7 +385,7 @@ install_prepare_libev_v2ray(){
elif [[ ${libev_v2ray} = "2" || ${libev_v2ray} = "3" ]]; then
if check_port_occupy "443"; then
echo -e "${Error} 检测到443端口被占用,请排查后重新运行." && exit 1
fi
fi
v2ray_plugin_prot_reset 443

while true
Expand All @@ -332,8 +410,8 @@ install_prepare_libev_v2ray(){
done
elif [[ ${libev_v2ray} = "4" ]]; then
if check_port_occupy "443"; then
echo -e "${Error} 检测到443端口被占用,请排查后重新运行." && exit 1
fi
echo -e "${Error} 检测到443端口被占用,请排查后重新运行." && exit 1
fi
while true
do
get_input_domain "请输入你的域名(CF->DNS->Proxied status:DNS-Only)"
Expand All @@ -345,7 +423,12 @@ install_prepare_libev_v2ray(){
fi

if is_dns_only ${domain_ip}; then
get_input_email_for_caddy
if [[ ${web_flag} = "1" ]]; then
get_input_email_for_caddy
elif [[ ${web_flag} = "2" ]]; then
acme_get_certificate_by_force
fi

get_input_ws_path_and_mirror_site
break
else
Expand All @@ -355,8 +438,8 @@ install_prepare_libev_v2ray(){
done
elif [[ ${libev_v2ray} = "5" ]]; then
if check_port_occupy "443"; then
echo -e "${Error} 检测到443端口被占用,请排查后重新运行." && exit 1
fi
echo -e "${Error} 检测到443端口被占用,请排查后重新运行." && exit 1
fi
while true
do
get_input_domain "请输入你的域名(CF->DNS->Proxied status:Proxied)"
Expand All @@ -368,7 +451,12 @@ install_prepare_libev_v2ray(){
fi

if is_cdn_proxied ${domain_ip}; then
choose_api_get_mode
if [[ ${web_flag} = "1" ]]; then
choose_api_get_mode
elif [[ ${web_flag} = "2" ]]; then
acme_get_certificate_by_api
fi

get_input_ws_path_and_mirror_site
break
else
Expand Down
66 changes: 52 additions & 14 deletions ss-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export PATH

# shell version
# ====================
SHELL_VERSION="2.3.2"
SHELL_VERSION="2.3.3"
# ====================


Expand Down Expand Up @@ -117,6 +117,11 @@ ONLINE_CADDY_DEBIAN_INIT_URL="${BASE_URL}/service/caddy_debian.sh"
LOCAL_CADDY_DEBIAN_INIT_PATH="./service/caddy_debian.sh"


# nginx
NGINX_BIN_PATH="/usr/sbin/nginx"
NGINX_CONFIG="/etc/nginx/nginx.conf"


# shadowsocks-libev Ciphers
SHADOWSOCKS_CIPHERS=(
rc4-md5
Expand Down Expand Up @@ -252,6 +257,15 @@ menu_status(){
else
echo -e " 当前状态: ${Green}已安装${suffix}${Red}未启动${suffix}"
fi
elif [[ -e ${BIN_PATH} ]] && [[ -e ${V2RAY_PLUGIN_BIN_PATH} ]] && [[ -e ${NGINX_BIN_PATH} ]]; then
V2_PID=`ps -ef |grep -v grep | grep v2ray-plugin |awk '{print $2}'`
NGINX_PID=`ps -ef |grep -v grep | grep nginx.conf |awk '{print $2}'`

if [[ ! -z ${SS_PID} ]] && [[ ! -z ${V2_PID} ]] && [[ ! -z ${NGINX_PID} ]]; then
echo -e " 当前状态: ${Green}已安装${suffix}${Green}已启动${suffix}"
else
echo -e " 当前状态: ${Green}已安装${suffix}${Red}未启动${suffix}"
fi
elif [[ -e ${BIN_PATH} ]] && [[ -e ${V2RAY_PLUGIN_BIN_PATH} ]]; then
V2_PID=`ps -ef |grep -v grep | grep v2ray-plugin |awk '{print $2}'`

Expand Down Expand Up @@ -929,10 +943,20 @@ config_ss(){
ss_v2ray_quic_tls_cdn_config
elif [[ ${libev_v2ray} == "4" ]]; then
ss_v2ray_ws_tls_web_config
caddy_config_none_cdn
if [[ ${web_flag} = "1" ]]; then
caddy_config_none_cdn
elif [[ ${web_flag} = "2" ]]; then
mirror_domain=$(echo ${mirror_site} | sed 's/https:\/\///g')
nginx_config
fi
elif [[ ${libev_v2ray} == "5" ]]; then
ss_v2ray_ws_tls_web_cdn_config
caddy_config_with_cdn
if [[ ${web_flag} = "1" ]]; then
caddy_config_with_cdn
elif [[ ${web_flag} = "2" ]]; then
mirror_domain=$(echo ${mirror_site} | sed 's/https:\/\///g')
nginx_config
fi
fi
elif [[ ${plugin_num} == "2" ]]; then
if [ ! -d "$(dirname ${KCPTUN_CONFIG})" ]; then
Expand Down Expand Up @@ -1014,18 +1038,24 @@ install_completed(){
elif [[ ${libev_v2ray} == "3" ]]; then
ss_v2ray_quic_tls_cdn_show
elif [[ ${libev_v2ray} == "4" ]]; then
# start caddy
/etc/init.d/caddy start > /dev/null 2>&1

if [[ ${web_flag} = "1" ]]; then
# start caddy
/etc/init.d/caddy start > /dev/null 2>&1
elif [[ ${web_flag} = "2" ]]; then
systemctl start nginx
fi
ss_v2ray_ws_tls_web_show
elif [[ ${libev_v2ray} == "5" ]]; then
# cloudflare email & api key
export CLOUDFLARE_EMAIL="${CF_Email}"
export CLOUDFLARE_API_KEY="${CF_Key}"

# start caddy
/etc/init.d/caddy start > /dev/null 2>&1

if [[ ${web_flag} = "1" ]]; then
# cloudflare email & api key
export CLOUDFLARE_EMAIL="${CF_Email}"
export CLOUDFLARE_API_KEY="${CF_Key}"

# start caddy
/etc/init.d/caddy start > /dev/null 2>&1
elif [[ ${web_flag} = "2" ]]; then
systemctl start nginx
fi
ss_v2ray_ws_tls_web_cdn_show
fi
elif [[ ${plugin_num} == "2" ]]; then
Expand Down Expand Up @@ -1118,7 +1148,12 @@ install_main(){
if [ "${plugin_num}" == "1" ]; then
improt_package "plugins" "v2ray_plugin_install.sh"
install_v2ray_plugin
choose_caddy_extension ${libev_v2ray}
if [[ ${web_flag} = "1" ]]; then
choose_caddy_extension ${libev_v2ray}
elif [[ ${web_flag} = "2" ]]; then
improt_package "tools" "nginx_install.sh"
install_nginx
fi
plugin_client_name="v2ray"
elif [ "${plugin_num}" == "2" ]; then
improt_package "plugins" "kcptun_install.sh"
Expand Down Expand Up @@ -1251,6 +1286,7 @@ do_start(){
goquiet_start
cloak_start
caddy_start
nginx_start
}

do_stop(){
Expand All @@ -1262,6 +1298,7 @@ do_stop(){
goquiet_stop
cloak_stop
caddy_stop
nginx_stop
}

do_restart(){
Expand Down Expand Up @@ -1328,6 +1365,7 @@ do_uninstall(){
goquiet_uninstall
cloak_uninstall
caddy_uninstall
nginx_uninstall
ipcalc_uninstall
echo -e "${Info} Shadowsocks 卸载成功."
}
Expand Down
47 changes: 47 additions & 0 deletions templates/config_file_templates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,53 @@ ss_v2ray_ws_tls_web_cdn_config(){
EOF
}

nginx_config(){
cat > /etc/nginx/nginx.conf<<-EOF
events {
worker_connections 4096; ## Default: 1024
}
http {
server {
listen 80;
server_name ${domain};
return 301 https://\$http_host\$request_uri;
}
server{
listen 443 ssl;
server_name ${domain};
ssl on;
ssl_certificate ${cerpath};
ssl_certificate_key ${keypath};
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
add_header Strict-Transport-Security "max-age=31536000";
location ${path} {
proxy_redirect off;
proxy_http_version 1.1;
proxy_pass http://localhost:${shadowsocksport};
proxy_set_header Host \$http_host;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
}
location / {
sub_filter ${mirror_domain} ${domain};
sub_filter_once off;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Referer ${mirror_site};
proxy_set_header Host ${mirror_domain};
proxy_pass ${mirror_site};
proxy_set_header Accept-Encoding "";
}
}
}
EOF
}

caddy_config_with_cdn(){
cat > ${CADDY_CONF_FILE}<<-EOF
${domain}:443 {
Expand Down
Loading

0 comments on commit 4f96f7a

Please sign in to comment.