#!/bin/bash : ' Copyright [2022] [HaoZi Technology Co., Ltd.] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ' HR="+----------------------------------------------------" ARCH=$(uname -m) OS=$(source /etc/os-release && { [[ "$ID" == "debian" ]] && echo "debian"; } || { [[ "$ID" == "centos" ]] || [[ "$ID" == "rhel" ]] || [[ "$ID" == "rocky" ]] || [[ "$ID" == "almalinux" ]] && echo "centos"; } || echo "unknown") cpuCore=$(cat /proc/cpuinfo | grep "processor" | wc -l) downloadUrl="https://dl.cdn.haozi.net" setupPath="/www" openrestyPath="${setupPath}/server/openresty" openrestyVersion="1.21.4.1" # 安装依赖 if [ "${OS}" == "centos" ]; then dnf install gcc gcc-c++ make tar unzip gd gd-devel git-core perl oniguruma oniguruma-devel bison yajl yajl-devel curl curl-devel libtermcap-devel ncurses-devel libevent-devel readline-devel libuuid-devel brotli-devel icu libicu libicu-devel openssl openssl-devel -y elif [ "${OS}" == "debian" ]; then apt install gcc g++ make tar unzip libgd3 libgd-dev git perl libonig-dev bison libyajl-dev curl libcurl4-openssl-dev libncurses5-dev libevent-dev libreadline-dev uuid-dev libbrotli-dev icu-devtools libicu-dev openssl libssl-dev -y else echo -e $HR echo "错误:耗子Linux面板不支持该系统" exit 1 fi # 准备目录 rm -rf ${openrestyPath} mkdir -p ${openrestyPath} cd ${openrestyPath} # 下载源码 wget -T 120 -O ${openrestyPath}/openresty-${openrestyVersion}.tar.gz ${downloadUrl}/panel/plugins/openresty/openresty-${openrestyVersion}.tar.gz tar -xvf openresty-${openrestyVersion}.tar.gz rm -f openresty-${openrestyVersion}.tar.gz mv openresty-${openrestyVersion} src cd src # openssl wget -T 120 -O openssl.tar.gz ${downloadUrl}/panel/plugins/openresty/openssl-1.1.1u.tar.gz tar -zxvf openssl.tar.gz rm -f openssl.tar.gz mv openssl-1.1.1u openssl rm -f openssl.tar.gz # pcre wget -T 60 -O pcre-8.45.tar.gz ${downloadUrl}/panel/plugins/openresty/pcre-8.45.tar.gz tar -zxvf pcre-8.45.tar.gz rm -f pcre-8.45.tar.gz mv pcre-8.45 pcre rm -f pcre-8.45.tar.gz # ngx_cache_purge wget -T 20 -O ngx_cache_purge.tar.gz ${downloadUrl}/panel/plugins/openresty/ngx_cache_purge-2.3.tar.gz tar -zxvf ngx_cache_purge.tar.gz rm -f ngx_cache_purge.tar.gz mv ngx_cache_purge-2.3 ngx_cache_purge rm -f ngx_cache_purge.tar.gz # nginx-sticky-module wget -T 20 -O nginx-sticky-module.zip ${downloadUrl}/panel/plugins/openresty/nginx-sticky-module.zip unzip -o nginx-sticky-module.zip rm -f nginx-sticky-module.zip # nginx-dav-ext-module wget -T 20 -O nginx-dav-ext-module-3.0.0.tar.gz ${downloadUrl}/panel/plugins/openresty/nginx-dav-ext-module-3.0.0.tar.gz tar -xvf nginx-dav-ext-module-3.0.0.tar.gz rm -f nginx-dav-ext-module-3.0.0.tar.gz mv nginx-dav-ext-module-3.0.0 nginx-dav-ext-module # waf cd ${openrestyPath} git clone -b lts https://ghproxy.com/https://github.com/ADD-SP/ngx_waf.git if [ "$?" != "0" ]; then echo -e $HR echo "错误:OpenResty waf拓展下载失败,请截图错误信息寻求帮助。" rm -rf ${openrestyPath} exit 1 fi git clone -b v2.3.0 https://ghproxy.com/https://github.com/troydhanson/uthash.git if [ "$?" != "0" ]; then echo -e $HR echo "错误:OpenResty waf拓展uthash下载失败,请截图错误信息寻求帮助。" rm -rf ${openrestyPath} exit 1 fi cd ngx_waf/inc wget -T 60 -O libinjection.zip ${downloadUrl}/panel/plugins/openresty/libinjection-3.10.0.zip unzip -o libinjection.zip mv libinjection-3.10.0 libinjection rm -rf libinjection.zip cd ../ make -j${cpuCore} if [ "$?" != "0" ]; then echo -e $HR echo "错误:OpenResty waf拓展初始化失败,请截图错误信息寻求帮助。" rm -rf ${openrestyPath} exit 1 fi cd ${openrestyPath}/src # brotli wget -T 20 -O ngx_brotli.zip ${downloadUrl}/panel/plugins/openresty/ngx_brotli-1.0.0rc.zip unzip -o ngx_brotli.zip mv ngx_brotli-1.0.0rc ngx_brotli cd ngx_brotli/deps rm -rf brotli wget -T 20 -O brotli.zip ${downloadUrl}/panel/plugins/openresty/brotli-1.0.9.zip unzip -o brotli.zip mv brotli-1.0.9 brotli cd ${openrestyPath}/src cd ${openrestyPath}/src export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH export LIB_UTHASH=${openrestyPath}/uthash ./configure --user=www --group=www --prefix=${openrestyPath} --with-luajit --add-module=${openrestyPath}/src/ngx_cache_purge --add-module=${openrestyPath}/src/nginx-sticky-module --with-openssl=${openrestyPath}/src/openssl --with-pcre=${openrestyPath}/src/pcre --with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt="-Wl,-E" --with-cc-opt="-O2 -std=gnu99" --with-cpu-opt="amd64" --with-http_dav_module --add-module=${openrestyPath}/src/nginx-dav-ext-module --add-module=${openrestyPath}/src/ngx_brotli --add-module=${openrestyPath}/ngx_waf make -j${cpuCore} if [ "$?" != "0" ]; then echo -e $HR echo "提示:OpenResty多线程编译失败,尝试单线程编译..." make if [ "$?" != "0" ]; then echo -e $HR echo "错误:OpenResty编译失败,请截图错误信息寻求帮助。" rm -rf ${openrestyPath} exit 1 fi fi make install if [ ! -f "${openrestyPath}/nginx/sbin/nginx" ]; then echo -e $HR echo "错误:OpenResty安装失败,请截图错误信息寻求帮助。" rm -rf ${openrestyPath} exit 1 fi # 设置软链接 ln -sf ${openrestyPath}/nginx/html ${openrestyPath}/html ln -sf ${openrestyPath}/nginx/conf ${openrestyPath}/conf ln -sf ${openrestyPath}/nginx/logs ${openrestyPath}/logs ln -sf ${openrestyPath}/nginx/sbin ${openrestyPath}/sbin ln -sf ${openrestyPath}/nginx/sbin/nginx /usr/bin/openresty rm -f ${openrestyPath}/conf/nginx.conf # 创建配置目录 cd ${openrestyPath} rm -f openresty-${openrestyVersion}.tar.gz rm -rf src mkdir -p /www/wwwroot/default mkdir -p /www/wwwlogs mkdir -p /www/server/vhost/openresty mkdir -p /www/server/vhost/openresty/rewrite mkdir -p /www/server/vhost/openresty/ssl # 写入主配置文件 cat >${openrestyPath}/conf/nginx.conf <\d+)$ { fastcgi_pass unix:/tmp/php-cgi-$version.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; } } include /www/server/vhost/openresty/*.conf; } EOF # 写入pathinfo配置文件 cat >${openrestyPath}/conf/pathinfo.conf <${openrestyPath}/html/index.html < 耗子Linux面板

耗子Linux面板

这是耗子Linux面板的OpenResty默认页面!

当您看到此页面,说明该域名尚未与站点绑定。

EOF # 写入站点停止页 cat >${openrestyPath}/html/stop.html < 网站已停止 - 耗子Linux面板

耗子Linux面板

该网站已被管理员停止访问!

当您看到此页面,说明该网站已被管理员停止对外访问,请联系管理员了解详情。

EOF # 处理文件权限 chmod 755 ${openrestyPath} chmod 644 ${openrestyPath}/html chmod -R 755 /www/wwwroot chown -R www:www /www/wwwroot chmod -R 644 /www/server/vhost # 写入无php配置文件 echo "" >${openrestyPath}/conf/enable-php-00.conf # 写入代理默认配置文件 cat >${openrestyPath}/conf/proxy.conf </lib/systemd/system/openresty.service <