-
Notifications
You must be signed in to change notification settings - Fork 5
/
nginx.sh
917 lines (840 loc) · 36.6 KB
/
nginx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
LANG=en_US.UTF-8
######### 检测是否是root用户 ###################
if [ "$(id -u)" -ne 0 ]; then
echo "此脚本需要以root用户运行。"
exit 1
fi
echo "你是以root用户运行此脚本。脚本继续运行"
public_file=/www/server/panel/install/public.sh
. $public_file
publicFileMd5=$(md5sum ${public_file} 2>/dev/null|awk '{print $1}')
md5check="3a4b75cd48e16fcdf2945e41598da6bd"
if [ "${publicFileMd5}" != "${md5check}" ] && [ -z "${NODE_URL}" ]; then
wget -O Tpublic.sh https://node.aapanel.com/install/public.sh -T 20;
publicFileMd5=$(md5sum Tpublic.sh 2>/dev/null|awk '{print $1}')
if [ "${publicFileMd5}" == "${md5check}" ]; then
\cp -rpa Tpublic.sh $public_file
fi
rm -f Tpublic.sh
. $public_file
fi
download_Url=$NODE_URL
tengine='3.1.0'
nginx_108='1.8.1'
nginx_112='1.12.2'
nginx_114='1.14.2'
nginx_115='1.15.10'
nginx_116='1.16.1'
nginx_117='1.17.10'
nginx_118='1.18.0'
nginx_119='1.19.8'
nginx_120='1.20.2'
nginx_121='1.21.4'
nginx_122='1.22.1'
nginx_123='1.23.4'
nginx_124='1.24.0'
nginx_125='1.25.5'
nginx_126='1.26.1'
openresty='1.25.3.1'
Root_Path=$(cat /var/bt_setupPath.conf)
Setup_Path=$Root_Path/server/nginx
run_path="/root"
Is_64bit=$(getconf LONG_BIT)
ARM_CHECK=$(uname -a | grep -E 'aarch64|arm|ARM')
if [ "$2" == "1.24" ];then
ARM_CHECK=""
JEM_CHECK="disable"
fi
LUAJIT_VER="2.0.4"
LUAJIT_INC_PATH="luajit-2.0"
if [ "${ARM_CHECK}" ]; then
LUAJIT_VER="2.1.0-beta3"
LUAJIT_INC_PATH="luajit-2.1"
fi
loongarch64Check=$(uname -a | grep loongarch64)
if [ "${loongarch64Check}" ]; then
wget -O nginx.sh ${download_Url}/install/0/loongarch64/nginx.sh && sh nginx.sh $1 $2
exit
fi
# if [ "$2" == "1.25" ];then
# ulimit -n 10240
# wget -O nginx.sh ${download_Url}/install/0/nginx5.sh
# . nginx.sh $1 $2
# exit
# fi
#HUAWEI_CLOUD_EULER=$(cat /etc/os-release |grep '"Huawei Cloud EulerOS 1')
#EULER_OS=$(cat /etc/os-release |grep "EulerOS 2.0 ")
#if [ "${HUAWEI_CLOUD_EULER}" ] || [ "${EULER_OS}" ];then
# wget -O nginx.sh ${download_Url}/install/1/nginx.sh && sh nginx.sh $1 $2
# exit
#fi
if [ -z "${cpuCore}" ]; then
cpuCore="1"
fi
Error_Send(){
MIN_O=$(date +%M)
if [ $((MIN_O % 2)) -eq 0 ]; then
exit 1
fi
if [ ! -f "/tmp/nginx_i.pl" ];then
touch /tmp/nginx_i.pl
TIME=$(date "+%Y-%m-%d %H:%M:%S")
P_VERSION=$(cat /www/server/panel/class/common.py|grep g.version|grep -oE 8.0.[0-9]+)
ls /etc/init.d/ | xargs -n 5 | pr -t -5 > /tmp/nginx_err.pl
cat /tmp/pack_i.pl >> /tmp/nginx_err.pl
cat /tmp/gd_i.pl >> /tmp/nginx_err.pl
tail -n 15 /tmp/nginx_config.pl /tmp/nginx_make.pl /tmp/nginx_install.pl >> /tmp/nginx_err.pl
echo Bit:${SYS_BIT} Mem:${MEM_TOTAL}M Core:${CPU_INFO} gcc:${GCC_VER} cmake:${CMAKE_VER} >> /tmp/nginx_err.pl
echo ${SYS_VERSION} ${SYS_INFO} >> /tmp/nginx_err.pl
echo "$nginxVersion install Failed" >> /tmp/nginx_err.pl
ERR_MSG=$(cat /tmp/nginx_err.pl)
rm -f /tmp/nginx_config.pl /tmp/nginx_make.pl /tmp/nginx_install.pl /tmp/nginx_err.pl /tmp/pack_i.pl /tmp/gd_i.pl
#### 此处会提交日志到宝塔服务器,注释掉 ###############
#curl --request POST \
# --url "http://api.bt.cn/bt_error/index.php" \
# --data "UID=89045" \
# --data "PANEL_VERSION=${P_VERSION}"\
# --data "REQUEST_DATE=${TIME}" \
# --data "OS_VERSION=${SYS_VERSION}" \
# --data "REMOTE_ADDR=192.168.168.1641" \
# --data "REQUEST_URI=nginx" \
# --data "USER_AGENT=${SYS_INFO}" \
# --data "ERROR_INFO=${ERR_MSG}" \
# --data "PACK_TIME=${TIME}" \
# --data "TYPE=3"
fi
exit 1
}
System_Lib() {
if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
Pack="gcc gcc-c++ curl curl-devel libtermcap-devel ncurses-devel libevent-devel readline-devel libuuid-devel gd-devel libxml2-devel libxslt-devel"
${PM} install ${Pack} -y
yum install zlib-devel -y
yum -y reinstall gcc gcc-c++ autoconf automake
yum reinstall gd gd-devel -y 2>&1 >> /tmp/pack_i.pl
ls /usr/include/gd.h /usr/lib64/libgd.so.3 2>&1 |tee /tmp/gd_i.pl
wget -O fix_install.sh $download_Url/tools/fix_install.sh
nohup bash fix_install.sh > /www/server/panel/install/fix.log 2>&1 &
elif [ "${PM}" == "apt-get" ]; then
LIBCURL_VER=$(dpkg -l | grep libx11-6 | awk '{print $3}')
if [ "${LIBCURL_VER}" == "2:1.6.9-2ubuntu1.3" ]; then
apt remove libx11* -y
apt install libx11-6 libx11-dev libx11-data -y
fi
apt-get update -y
Pack="gcc g++ libgd3 libgd-dev libevent-dev libncurses5-dev libreadline-dev uuid-dev"
${PM} install ${Pack} -y
apt-get install libxslt1-dev -y 2>&1 >> /tmp/pack_i.pl
apt-get install libgd-dev -y 2>&1 >> /tmp/pack_i.pl
apt-get install libxml2-dev -y 2>&1 >> /tmp/pack_i.pl
apt-get install zlib1g-dev -y
fi
}
Service_Add() {
if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
chkconfig --add nginx
chkconfig --level 2345 nginx on
elif [ "${PM}" == "apt-get" ]; then
update-rc.d nginx defaults
fi
if [ "$?" == "127" ];then
wget -O /usr/lib/systemd/system/nginx.service ${download_Url}/init/systemd/nginx.service
systemctl enable nginx.service
fi
}
Service_Del() {
if [ "${PM}" == "yum" ] || [ "${PM}" == "dnf" ]; then
chkconfig --del nginx
chkconfig --level 2345 nginx off
elif [ "${PM}" == "apt-get" ]; then
update-rc.d nginx remove
fi
}
Set_Time() {
BASH_DATE=$(stat nginx.sh | grep Modify | awk '{print $2}' | tr -d '-')
SYS_DATE=$(date +%Y%m%d)
[ "${SYS_DATE}" -lt "${BASH_DATE}" ] && date -s "$(curl https://www.bt.cn//api/index/get_date)"
}
Install_Jemalloc() {
if [ ! -f '/usr/local/lib/libjemalloc.so' ]; then
wget -O jemalloc-5.0.1.tar.bz2 ${download_Url}/src/jemalloc-5.0.1.tar.bz2
tar -xvf jemalloc-5.0.1.tar.bz2
cd jemalloc-5.0.1
./configure
make && make install
ldconfig
cd ..
rm -rf jemalloc*
fi
}
Install_LuaJIT2(){
LUAJIT_INC_PATH="luajit-2.1"
wget -c -O luajit2-2.1-20230410.zip ${download_Url}/src/luajit2-2.1-20230410.zip
unzip -o luajit2-2.1-20230410.zip
cd luajit2-2.1-20230410
make -j${cpuCore}
make install
cd ..
rm -rf luajit2-2.1-20230410*
ln -sf /usr/local/lib/libluajit-5.1.so.2 /usr/local/lib64/libluajit-5.1.so.2
LD_SO_CHECK=$(cat /etc/ld.so.conf|grep /usr/local/lib)
if [ -z "${LD_SO_CHECK}" ];then
echo "/usr/local/lib" >>/etc/ld.so.conf
fi
ldconfig
}
Install_LuaJIT() {
if [ "${version}" == "1.23" ] || [ "${version}" == "1.24" ] || [ "${version}" == "tengine" ] || [ "${version}" == "1.25" ] || [ "${version}" == "1.26" ];then
Install_LuaJIT2
return
fi
OEPN_LUAJIT=$(cat /usr/local/include/luajit-2.1/luajit.h|grep 2022)
if [ ! -f '/usr/local/lib/libluajit-5.1.so' ] || [ ! -f "/usr/local/include/${LUAJIT_INC_PATH}/luajit.h" ] || [ "${OEPN_LUAJIT}" ]; then
wget -c -O LuaJIT-${LUAJIT_VER}.tar.gz ${download_Url}/install/src/LuaJIT-${LUAJIT_VER}.tar.gz -T 10
tar xvf LuaJIT-${LUAJIT_VER}.tar.gz
cd LuaJIT-${LUAJIT_VER}
make linux
make install
cd ..
rm -rf LuaJIT-*
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/${LUAJIT_INC_PATH}/
ln -sf /usr/local/lib/libluajit-5.1.so.2 /usr/local/lib64/libluajit-5.1.so.2
LD_SO_CHECK=$(cat /etc/ld.so.conf|grep /usr/local/lib)
if [ -z "${LD_SO_CHECK}" ];then
echo "/usr/local/lib" >>/etc/ld.so.conf
fi
ldconfig
fi
}
Install_cjson() {
if [ ! -f /usr/local/lib/lua/5.1/cjson.so ]; then
wget -O lua-cjson-2.1.0.tar.gz $download_Url/install/src/lua-cjson-2.1.0.tar.gz -T 20
tar xvf lua-cjson-2.1.0.tar.gz
rm -f lua-cjson-2.1.0.tar.gz
cd lua-cjson-2.1.0
make
make install
cd ..
rm -rf lua-cjson-2.1.0
fi
}
Download_Src() {
mkdir -p ${Setup_Path}
cd ${Setup_Path}
rm -rf ${Setup_Path}/src
if [ "${version}" == "tengine" ] || [ "${version}" == "openresty" ]; then
wget -O ${Setup_Path}/src.tar.gz ${download_Url}/src/${version}-${nginxVersion}.tar.gz -T20
tar -xvf src.tar.gz
mv ${version}-${nginxVersion} src
################################# 替换nginx版本信息 替换错误页nginx名称和版本增加安全性 #################################################################
sed -i 's/static u_char ngx_http_server_string\[] = "Server: nginx" CRLF;/static u_char ngx_http_server_string\[] = "Server: OWASP WAF" CRLF;/g' /www/server/nginx/src/src/http/ngx_http_header_filter_module.c
sed -i 's/static u_char ngx_http_server_full_string\[] = "Server: " NGINX_VER CRLF;/static u_char ngx_http_server_full_string\[] = "Server: OWASP WAF" CRLF;/g' /www/server/nginx/src/src/http/ngx_http_header_filter_module.c
sed -i 's/static u_char ngx_http_server_build_string\[] = "Server: " NGINX_VER_BUILD CRLF;/static u_char ngx_http_server_build_string\[] = "Server: OWASP WAF" CRLF;/g' /www/server/nginx/src/src/http/ngx_http_header_filter_module.c
else
wget -O ${Setup_Path}/src.tar.gz ${download_Url}/src/nginx-${nginxVersion}.tar.gz -T20
tar -xvf src.tar.gz
tar -xvf src.tar.gz
mv nginx-${nginxVersion} src
################################# 替换nginx版本信息 替换错误页nginx名称和版本增加安全性 #################################################################
sed -i 's/static u_char ngx_http_server_string\[] = "Server: nginx" CRLF;/static u_char ngx_http_server_string\[] = "Server: OWASP WAF" CRLF;/g' /www/server/nginx/src/src/http/ngx_http_header_filter_module.c
sed -i 's/static u_char ngx_http_server_full_string\[] = "Server: " NGINX_VER CRLF;/static u_char ngx_http_server_full_string\[] = "Server: OWASP WAF" CRLF;/g' /www/server/nginx/src/src/http/ngx_http_header_filter_module.c
sed -i 's/static u_char ngx_http_server_build_string\[] = "Server: " NGINX_VER_BUILD CRLF;/static u_char ngx_http_server_build_string\[] = "Server: OWASP WAF" CRLF;/g' /www/server/nginx/src/src/http/ngx_http_header_filter_module.c
fi
cd src
if [ -z "${GMSSL}" ]; then
TLSv13_NGINX=$(echo ${nginxVersion} | tr -d '.' | cut -c 1-3)
if [ "${TLSv13_NGINX}" -ge "115" ] && [ "${TLSv13_NGINX}" != "181" ]; then
opensslVer="1.1.1q"
else
opensslVer="1.0.2u"
fi
# if [ "$version" == "1.23" ];then
# opensslVer="3.0.5"
# fi
################################### 更新openssl 3.0.14版本 ##############################################
wget -O openssl.tar.gz https://www.openssl.org/source/openssl-3.0.14.tar.gz -T 20
tar -xvf openssl.tar.gz
mv openssl-3.0.14 openssl
rm -f openssl.tar.gz
else
wget -O GmSSL-master.zip ${download_Url}/src/GmSSL-master.zip
unzip GmSSL-master.zip
mv GmSSL-master openssl
rm -f GmSSL-master.zip
fi
######################################## 更新pcre-8.45版本 ###########################################
pcre_version="8.45"
wget -O pcre-8.45.zip https://nchc.dl.sourceforge.net/project/pcre/pcre/8.45/pcre-8.45.zip -T 20
unzip -o pcre-8.45.zip
mv pcre-8.45 pcre
rm -f pcre-8.45.zip
# ################################ 添加brotli模块 ##############################################
#下载brotli
git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli
#更新brotli
git submodule update --init
cd /www/server/nginx/src
wget -O ngx_cache_purge.tar.gz ${download_Url}/src/ngx_cache_purge-2.3.tar.gz
tar -zxvf ngx_cache_purge.tar.gz
mv ngx_cache_purge-2.3 ngx_cache_purge
rm -f ngx_cache_purge.tar.gz
wget -O nginx-sticky-module.zip ${download_Url}/src/nginx-sticky-module.zip
unzip -o nginx-sticky-module.zip
rm -f nginx-sticky-module.zip
wget -O nginx-http-concat.zip ${download_Url}/src/nginx-http-concat-1.2.2.zip
unzip -o nginx-http-concat.zip
mv nginx-http-concat-1.2.2 nginx-http-concat
rm -f nginx-http-concat.zip
#lua_nginx_module
LuaModVer="0.10.13"
if [ "${version}" == "1.23" ] || [ "${version}" == "1.24" ] || [ "${version}" == "tengine" ] || [ "${version}" == "1.25" ] || [ "${version}" == "1.26" ];then
LuaModVer="0.10.24"
fi
wget -c -O lua-nginx-module-${LuaModVer}.zip ${download_Url}/src/lua-nginx-module-${LuaModVer}.zip
unzip -o lua-nginx-module-${LuaModVer}.zip
mv lua-nginx-module-${LuaModVer} lua_nginx_module
rm -f lua-nginx-module-${LuaModVer}.zip
#ngx_devel_kit
NgxDevelKitVer="0.3.1"
wget -c -O ngx_devel_kit-${NgxDevelKitVer}.zip ${download_Url}/src/ngx_devel_kit-${NgxDevelKitVer}.zip
unzip -o ngx_devel_kit-${NgxDevelKitVer}.zip
mv ngx_devel_kit-${NgxDevelKitVer} ngx_devel_kit
rm -f ngx_devel_kit-${NgxDevelKitVer}.zip
#nginx-dav-ext-module
NgxDavVer="3.0.0"
wget -c -O nginx-dav-ext-module-${NgxDavVer}.tar.gz ${download_Url}/src/nginx-dav-ext-module-${NgxDavVer}.tar.gz
tar -xvf nginx-dav-ext-module-${NgxDavVer}.tar.gz
mv nginx-dav-ext-module-${NgxDavVer} nginx-dav-ext-module
rm -f nginx-dav-ext-module-${NgxDavVer}.tar.gz
wget -c -O ngx_http_substitutions_filter_module-master.zip ${download_Url}/src/ngx_http_substitutions_filter_module-master.zip
unzip -o ngx_http_substitutions_filter_module-master.zip
rm -f ngx_http_substitutions_filter_module-master.zip
if [ "${Is_64bit}" = "64" ]; then
if [ "${version}" == "1.15" ] || [ "${version}" == "1.17" ] || [ "${version}" == "tengine" ]; then
NGX_PAGESPEED_VAR="1.13.35.2"
wget -O ngx-pagespeed-${NGX_PAGESPEED_VAR}.tar.gz ${download_Url}/src/ngx-pagespeed-${NGX_PAGESPEED_VAR}.tar.gz
tar -xvf ngx-pagespeed-${NGX_PAGESPEED_VAR}.tar.gz
mv ngx-pagespeed-${NGX_PAGESPEED_VAR} ngx-pagespeed
rm -f ngx-pagespeed-${NGX_PAGESPEED_VAR}.tar.gz
fi
fi
}
Install_Configure() {
Run_User="www"
wwwUser=$(cat /etc/passwd | grep www)
if [ "${wwwUser}" == "" ]; then
groupadd ${Run_User}
useradd -s /sbin/nologin -g ${Run_User} ${Run_User}
fi
[ -f "/www/server/panel/install/nginx_prepare.sh" ] && . /www/server/panel/install/nginx_prepare.sh
[ -f "/www/server/panel/install/nginx_configure.pl" ] && ADD_EXTENSION=$(cat /www/server/panel/install/nginx_configure.pl)
if [ -f "/usr/local/lib/libjemalloc.so" ] && [ -z "${ARM_CHECK}" ] && [ -z "${JEM_CHECK}" ]; then
jemallocLD="--with-ld-opt="-ljemalloc""
fi
if [ "${version}" == "1.8" ]; then
ENABLE_HTTP2="--with-http_spdy_module"
else
ENABLE_HTTP2="--with-http_v2_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module"
fi
WebDav_NGINX=$(echo ${nginxVersion} | tr -d '.' | cut -c 1-3)
if [ "${WebDav_NGINX}" -ge "114" ] && [ "${WebDav_NGINX}" != "181" ]; then
ENABLE_WEBDAV="--with-http_dav_module --add-module=${Setup_Path}/src/nginx-dav-ext-module"
fi
if [ "${version}" == "openresty" ]; then
ENABLE_LUA="--with-luajit"
elif [ -z "${ARM_CHECK}" ] && [ -f "/usr/local/include/${LUAJIT_INC_PATH}/luajit.h" ]; then
ENABLE_LUA="--add-module=${Setup_Path}/src/ngx_devel_kit --add-module=${Setup_Path}/src/lua_nginx_module"
fi
ENABLE_STICKY="--add-module=${Setup_Path}/src/nginx-sticky-module"
if [ "$version" == "1.23" ] || [ "$version" == "1.24" ] || [ "${version}" == "tengine" ] || [ "${version}" == "openresty" ] || [ "$version" == "1.25" ] || [ "${version}" == "1.26" ];then
ENABLE_STICKY=""
fi
if [ "$version" == "1.25" ] || [ "${version}" == "1.26" ];then
ENABLE_HTTP3="--with-http_v3_module"
fi
name=nginx
i_path=/www/server/panel/install/$name
i_args=$(cat $i_path/config.pl | xargs)
i_make_args=""
for i_name in $i_args; do
init_file=$i_path/$i_name/init.sh
if [ -f $init_file ]; then
bash $init_file
fi
args_file=$i_path/$i_name/args.pl
if [ -f $args_file ]; then
args_string=$(cat $args_file)
i_make_args="$i_make_args $args_string"
fi
done
cd ${Setup_Path}/src
# if [ "${GMSSL}" ];then
# sed -i "s/$OPENSSL\/.openssl\//$OPENSSL\//g" auto/lib/openssl/conf
# fi
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/${LUAJIT_INC_PATH}/
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
# 删除弃用的ipv6
# 删除自带的webdav模块 ${ENABLE_WEBDAV}
# 添加优化参数 --with-threads --with-file-aio --with-cc-opt='-O2 -fPIE --param=ssp-buffer-size=4 -fstack-protector -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-E -Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now'
# 添加ngx_brotli模块 --add-module=/www/server/nginx/src/ngx_brotli
./configure --user=www --group=www --with-threads --with-file-aio --with-cc-opt='-O2 -fPIE --param=ssp-buffer-size=4 -fstack-protector -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-E -Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=${Setup_Path} ${ENABLE_LUA} --add-module=${Setup_Path}/src/ngx_cache_purge ${ENABLE_STICKY} --with-openssl=${Setup_Path}/src/openssl --with-pcre=pcre ${ENABLE_HTTP2} --with-http_stub_status_module --with-http_ssl_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --add-module=${Setup_Path}/src/ngx_http_substitutions_filter_module-master --add-module=/www/server/nginx/src/ngx_brotli ${jemallocLD} ${ENABLE_NGX_PAGESPEED} ${ENABLE_HTTP3} ${ADD_EXTENSION} ${i_make_args} 2>&1|tee /tmp/nginx_config.pl
make -j${cpuCore} 2>&1|tee /tmp/nginx_make.pl
}
Install_Nginx() {
make install 2>&1|tee /tmp/nginx_install.pl
if [ "${version}" == "openresty" ]; then
ln -sf /www/server/nginx/nginx/html /www/server/nginx/html
ln -sf /www/server/nginx/nginx/conf /www/server/nginx/conf
ln -sf /www/server/nginx/nginx/logs /www/server/nginx/logs
ln -sf /www/server/nginx/nginx/sbin /www/server/nginx/sbin
if [ -d "/www/server/btwaf" ]; then
\cp -rpa /www/server/nginx/lualib/* /www/server/btwaf
elif [ -d "/www/server/free_waf" ];then
\cp -rpa /www/server/nginx/lualib/* /www/server/free_waf
fi
fi
if [ ! -f "${Setup_Path}/sbin/nginx" ]; then
echo '========================================================'
GetSysInfo
echo -e "ERROR: nginx-${nginxVersion} installation failed."
if [ -z "${SYS_VERSION}" ];then
echo -e "============================================"
echo -e "检测到为非常用系统安装"
echo -e "如无法正常安装,建议更换至Centos-7或Debian-10+或Ubuntu-20+系统安装宝塔面板"
echo -e "详情请查看系统兼容表:https://docs.qq.com/sheet/DUm54VUtyTVNlc21H?tab=BB08J2"
echo -e "特殊情况可通过以下联系方式寻求安装协助情况"
echo -e "============================================"
fi
echo -e "安装失败,请截图以上报错信息发帖至论坛www.bt.cn/bbs求助"
rm -rf ${Setup_Path}
if [ ! -f "/www/server/panel/install/nginx_down.pl" ];then
FILE_KEY=("./configure: error: no /www/server/nginx/src/ngx_devel_kit/config was found" "./configure: No such file or directory" "./configure: error: no /www/server/nginx/src/ngx_http_substitutions_filter_module-master/config was found" "./configure: error: no /www/server/nginx/src/nginx-dav-ext-module/config was found" "auto/options: No such file or directory" "./configure: error: no /www/server/nginx/src/ngx_cache_purge/config was found" "/www/server/nginx/src/lua_nginx_module/config was found")
for key in "${FILE_KEY[@]}"; do
if grep -q "$key" /tmp/nginx_config.pl; then
echo -e "检测到文件下载不完整导致安装失败,请尝试重新安装nginx看是否正常"
echo -e "或使用极速安装看是否正常"
touch /www/server/panel/install/nginx_down.pl
exit 1
fi
done
fi
if [ "${i_make_args}" ];then
echo -e "检测到使用自定义编译参数进行安装nginx"
echo -e "请根据报错自行排查问题,或取消自定义编译参数重新安装"
exit 1
fi
Centos8Check=$(cat /etc/redhat-release | grep ' 8.' | grep -iE 'centos')
if [ "${Centos8Check}" ];then
echo -e "Centos8官方已经停止支持"
echo -e "如是新安装系统服务器建议更换至Centos-7/Debian-11/Ubuntu-22系统安装宝塔面板"
exit 1
fi
WSL_CHECK=$(uname -a|grep Microsoft)
if [ "${WSL_CHECK}" ];then
echo -e "宝塔未兼容测试过Microsoft WSL子系统进行安装"
echo -e "建议使用虚拟机安装ubuntu-22安装宝塔面板"
exit 1
fi
VELINUX_CHECK=$(uname -a|grep velinux1)
if [ "$VELINUX_CHECK" ];then
echo -e "宝塔未兼容测试过velinux系统进行安装"
echo -e "建议更换至Centos-7或Debian-10+或Ubuntu-20+系统安装宝塔面板板"
exit 1
fi
rockchip64_CHECK=$(uname -a|grep rockchip64)
if [ "$VELINUX_CHECK" ];then
echo -e "宝塔未兼容测试过rockchip64系统进行安装"
echo -e "建议更换至Centos-7或Debian-10+或Ubuntu-20+服务器系统安装宝塔面板板"
exit 1
fi
KALI_CHECK=$(uname -a|grep Kali)
if [ "${WSL_CHECK}" ];then
echo -e "宝塔未兼容测试过Kali系统进行安装"
echo -e "建议更换至Centos-7或Debian-10+或Ubuntu-20+系统安装宝塔面板板"
exit 1
fi
ARMBIAN_CHECK=$(uname -a|grep Armbian)
if [ "${ARMBIAN_CHECK}" ];then
echo -e "宝塔未详细兼容测试过Armbian系统进行安装"
echo -e "建议更换至Centos-7或Debian-10+或Ubuntu-20+系统安装宝塔面板板"
exit 1
fi
RJ3328_CHECK=$(uname -a|grep rk3328)
if [ "${RJ3328_CHECK}" ];then
echo -e "宝塔未兼容测试过电视盒子进行安装"
echo -e "建议更换至Centos-7或Debian-10+或Ubuntu-20+系统安装宝塔面板板"
exit 1
fi
XIAOMI_CHECK=$(uname -a|grep xiaomi)
if [ "${XIAOMI_CHECK}" ];then
echo -e "宝塔未兼容测试过安卓手机进行安装"
echo -e "建议更换至Centos-7或Debian-10+或Ubuntu-20+服务器系统安装宝塔面板板"
exit 1
fi
if [ -f "/etc/redhat-release" ];then
LINUX_KIT_CHECK=$(uname -a|grep linuxkit)
if [ "${LINUX_KIT_CHECK}" ];then
echo -e "宝塔未兼容测试过linuxkit(docker)环境下进行安装"
echo -e "建议更换至服务器系统Centos-7或Debian-10+或Ubuntu-20+系统安装宝塔面板板"
exit 1
fi
BBR_CHECK=$(uname -a|grep bbrplus)
if [ "${BBR_CHECK}" ];then
echo -e "检测已使用bbr更新过内核,建议更新完内核在安装宝塔面板然后再安装软件"
echo -e "或如需高版本内核,可使用Ubuntu-22/Debian-12进行安装宝塔面板"
exit 1
fi
ELREPO_CHECK=$(uname -a|grep elrepo)
if [ "${ELREPO_CHECK}" ];then
echo -e "检测更新过内核,建议更新完内核在安装宝塔面板然后再安装软件"
echo -e "或如需高版本内核,可使用Ubuntu-22/Debian-12进行安装宝塔面板"
exit 1
fi
fi
if [ "${PM}" == "apt-get" ];then
UBUNTU_23_CHECK=$(cat /etc/issue|grep Ubuntu|grep 23)
if [ "${UBUNTU_23_CHECK}" ];then
echo -e "宝塔未兼容测试过Ubuntu-23(预览版)环境下进行安装"
echo -e "建议更换至服务器系统Centos-7或Debian-12或Ubuntu-22系统安装宝塔面板板"
exit 1
fi
DEBIAN_9_CHECK=$(cat /etc/issue|grep Debian|grep 9)
if [ "${UBUNTU_23_CHECK}" ];then
echo -e "Debian-9官方已经不在支持"
echo -e "建议更换至服务器系统Centos-7或Debian-12或Ubuntu-22系统安装宝塔面板板"
exit 1
fi
fi
Error_Send
fi
if [ "${version}" == "1.23" ] || [ "${version}" == "1.24" ] || [ "${version}" == "tengine" ] || [ "${version}" == "1.25" ] || [ "${version}" == "1.26" ];then
wget -c -O lua-resty-core-0.1.26.zip ${download_Url}/src/lua-resty-core-0.1.26.zip
unzip lua-resty-core-0.1.26.zip
cd lua-resty-core-0.1.26
make install PREFIX=/www/server/nginx
cd ..
rm -rf lua-resty-core-0.1.26*
wget -c -O lua-resty-lrucache-0.13.zip ${download_Url}/src/lua-resty-lrucache-0.13.zip
unzip lua-resty-lrucache-0.13.zip
cd lua-resty-lrucache-0.13
make install PREFIX=/www/server/nginx
cd ..
rm -rf lua-resty-core-0.1.26*
fi
\cp -rpa ${Setup_Path}/sbin/nginx /www/backup/nginxBak
chmod -x /www/backup/nginxBak
md5sum ${Setup_Path}/sbin/nginx > /www/server/panel/data/nginx_md5.pl
ln -sf ${Setup_Path}/sbin/nginx /usr/bin/nginx
rm -f ${Setup_Path}/conf/nginx.conf
cd ${Setup_Path}
rm -f src.tar.gz
}
Update_Nginx() {
if [ "${nginxVersion}" = "openresty" ]; then
make install
echo -e "done"
nginx -v
echo "${nginxVersion}" >${Setup_Path}/version.pl
rm -f ${Setup_Path}/version_check.pl
exit
fi
if [ ! -f ${Setup_Path}/src/objs/nginx ]; then
echo '========================================================'
GetSysInfo
echo -e "ERROR: nginx-${nginxVersion} installation failed."
echo -e "升级失败,请截图以上报错信息发帖至论坛www.bt.cn/bbs求助"
exit 1
fi
sleep 1
/etc/init.d/nginx stop
mv -f ${Setup_Path}/sbin/nginx ${Setup_Path}/sbin/nginxBak
\cp -rfp ${Setup_Path}/src/objs/nginx ${Setup_Path}/sbin/
if [ "${version}" == "1.25" ] || [ "${version}" == "1.26" ];then
if [ "${version}" == "1.23" ] || [ "${version}" == "1.24" ] || [ "${version}" == "tengine" ] || [ "${version}" == "1.25" ] || [ "${version}" == "1.26" ];then
wget -c -O lua-resty-core-0.1.26.zip ${download_Url}/src/lua-resty-core-0.1.26.zip
unzip lua-resty-core-0.1.26.zip
cd lua-resty-core-0.1.26
make install PREFIX=/www/server/nginx
cd ..
rm -rf lua-resty-core-0.1.26*
wget -c -O lua-resty-lrucache-0.13.zip ${download_Url}/src/lua-resty-lrucache-0.13.zip
unzip lua-resty-lrucache-0.13.zip
cd lua-resty-lrucache-0.13
make install PREFIX=/www/server/nginx
cd ..
rm -rf lua-resty-core-0.1.26*
fi
wget -O /etc/init.d/nginx ${download_Url}/init/124nginx.init
fi
sleep 1
/etc/init.d/nginx start
rm -rf ${Setup_Path}/src
nginx -v
echo "${nginxVersion}" >${Setup_Path}/version.pl
rm -f ${Setup_Path}/version_check.pl
if [ "${version}" == "tengine" ]; then
echo "2.2.4(${tengine})" >${Setup_Path}/version_check.pl
fi
exit
}
Set_Conf() {
Default_Website_Dir=$Root_Path'/wwwroot/default'
mkdir -p ${Default_Website_Dir}
mkdir -p ${Root_Path}/wwwlogs
mkdir -p ${Setup_Path}/conf/vhost
mkdir -p /usr/local/nginx/logs
mkdir -p ${Setup_Path}/conf/rewrite
mkdir -p /www/wwwlogs/load_balancing/tcp
mkdir -p /www/server/panel/vhost/nginx/tcp
wget -O ${Setup_Path}/conf/nginx.conf ${download_Url}/conf/nginx1.conf -T20
wget -O ${Setup_Path}/conf/pathinfo.conf ${download_Url}/conf/pathinfo.conf -T20
wget -O ${Setup_Path}/conf/enable-php.conf ${download_Url}/conf/enable-php.conf -T20
wget -O ${Setup_Path}/html/index.html ${download_Url}/error/index.html -T 20
chmod 755 /www/server/nginx/
chmod 755 /www/server/nginx/html/
chmod 755 /www/wwwroot/
chmod 644 /www/server/nginx/html/*
cat >${Root_Path}/server/panel/vhost/nginx/phpfpm_status.conf <<EOF
server {
listen 80;
server_name 127.0.0.1;
allow 127.0.0.1;
location /nginx_status {
stub_status on;
access_log off;
}
EOF
echo "" >/www/server/nginx/conf/enable-php-00.conf
for phpV in 52 53 54 55 56 70 71 72 73 74 75 80 81 82 83; do
cat >${Setup_Path}/conf/enable-php-${phpV}.conf <<EOF
location ~ [^/]\.php(/|$)
{
try_files \$uri =404;
fastcgi_pass unix:/tmp/php-cgi-${phpV}.sock;
fastcgi_index index.php;
include fastcgi.conf;
include pathinfo.conf;
}
EOF
cat >>${Root_Path}/server/panel/vhost/nginx/phpfpm_status.conf <<EOF
location /phpfpm_${phpV}_status {
fastcgi_pass unix:/tmp/php-cgi-${phpV}.sock;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME \$fastcgi_script_name;
}
EOF
done
echo \} >>${Root_Path}/server/panel/vhost/nginx/phpfpm_status.conf
cat >${Setup_Path}/conf/proxy.conf <<EOF
proxy_temp_path ${Setup_Path}/proxy_temp_dir;
proxy_cache_path ${Setup_Path}/proxy_cache_dir levels=1:2 keys_zone=cache_one:20m inactive=1d max_size=5g;
client_body_buffer_size 512k;
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 60;
proxy_buffer_size 32k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_next_upstream error timeout invalid_header http_500 http_503 http_404;
proxy_cache cache_one;
EOF
cat >${Setup_Path}/conf/luawaf.conf <<EOF
lua_shared_dict limit 10m;
lua_package_path "/www/server/nginx/waf/?.lua";
init_by_lua_file /www/server/nginx/waf/init.lua;
access_by_lua_file /www/server/nginx/waf/waf.lua;
EOF
mkdir -p /www/wwwlogs/waf
chown www.www /www/wwwlogs/waf
chmod 744 /www/wwwlogs/waf
mkdir -p /www/server/panel/vhost
#wget -O waf.zip ${download_Url}/install/waf/waf.zip
#unzip -o waf.zip -d $Setup_Path/ >/dev/null
if [ ! -d "/www/server/panel/vhost/wafconf" ]; then
mv $Setup_Path/waf/wafconf /www/server/panel/vhost/wafconf
fi
sed -i "s#include vhost/\*.conf;#include /www/server/panel/vhost/nginx/\*.conf;#" ${Setup_Path}/conf/nginx.conf
sed -i "s#/www/wwwroot/default#/www/server/phpmyadmin#" ${Setup_Path}/conf/nginx.conf
sed -i "/pathinfo/d" ${Setup_Path}/conf/enable-php.conf
sed -i "s/#limit_conn_zone.*/limit_conn_zone \$binary_remote_addr zone=perip:10m;\n\tlimit_conn_zone \$server_name zone=perserver:10m;/" ${Setup_Path}/conf/nginx.conf
sed -i "s/mime.types;/mime.types;\n\t\tinclude proxy.conf;\n/" ${Setup_Path}/conf/nginx.conf
#if [ "${nginx_version}" == "1.12.2" ] || [ "${nginx_version}" == "openresty" ] || [ "${nginx_version}" == "1.14.2" ];then
sed -i "s/mime.types;/mime.types;\n\t\t#include luawaf.conf;\n/" ${Setup_Path}/conf/nginx.conf
#fi
PHPVersion=""
for phpVer in 52 53 54 55 56 70 71 72 73 74 80; do
if [ -d "/www/server/php/${phpVer}/bin" ]; then
PHPVersion=${phpVer}
fi
done
if [ "${PHPVersion}" ]; then
\cp -r -a ${Setup_Path}/conf/enable-php-${PHPVersion}.conf ${Setup_Path}/conf/enable-php.conf
fi
if [ ! -f "${Setup_Path}/conf/enable-php.conf" ];then
touch ${Setup_Path}/conf/enable-php.conf
fi
AA_PANEL_CHECK=$(cat /www/server/panel/config/config.json | grep "English")
if [ "${AA_PANEL_CHECK}" ]; then
#\cp -rf /www/server/panel/data/empty.html /www/server/nginx/html/index.html
wget -O /www/server/nginx/html/index.html ${download_Url}/error/index_en_nginx.html -T 20
chmod 644 /www/server/nginx/html/index.html
wget -O /www/server/panel/vhost/nginx/0.default.conf ${download_Url}/conf/nginx/en.0.default.conf
for phpV in 52 53 54 55 56 70 71 72 73 74 75 80 81 82 83; do
wget -O ${Setup_Path}/conf/enable-php-${phpV}-wpfastcgi.conf ${download_Url}/install/wordpress_conf/nginx/enable-php-${phpV}-wpfastcgi.conf
done
fi
wget -O /etc/init.d/nginx ${download_Url}/init/nginx.init -T 20
if [ "${version}" == "1.23" ] || [ "${version}" == "1.24" ] || [ "${version}" == "tengine" ] || [ "${version}" == "1.25" ] || [ "${version}" == "1.26" ];then
if [ -d "/www/server/btwaf" ];then
rm -rf /www/server/btwaf/ngx
rm -rf /www/server/btwaf/resty
\cp -rpa /www/server/nginx/lib/lua/* /www/server/btwaf
elif [ -d "/www/server/free_waf" ];then
rm -rf /www/server/btwaf/ngx
rm -rf /www/server/btwaf/resty
\cp -rpa /www/server/nginx/lib/lua/* /www/server/free_waf
else
sed -i "/lua_package_path/d" /www/server/nginx/conf/nginx.conf
sed -i '/include proxy\.conf;/a \ lua_package_path "/www/server/nginx/lib/lua/?.lua;;";' /www/server/nginx/conf/nginx.conf
fi
wget -O /etc/init.d/nginx ${download_Url}/init/124nginx.init -T 20
fi
if [ "${version}" == "1.25" ] || [ "${version}" == "1.26" ];then
HTTP_POST_CHECK=$(cat /www/server/nginx/conf/fastcgi.conf|grep "HTTP_HOST")
if [ -z "${HTTP_POST_CHECK}" ];then
echo "fastcgi_param HTTP_HOST \$host;" >> /www/server/nginx/conf/fastcgi.conf
fi
fi
chmod +x /etc/init.d/nginx
}
Set_Version() {
if [ "${version}" == "tengine" ]; then
echo "-Tengine2.2.3" >${Setup_Path}/version.pl
echo "2.2.4(${tengine})" >${Setup_Path}/version_check.pl
elif [ "${version}" == "openresty" ]; then
echo "openresty" >${Setup_Path}/version.pl
echo "openresty-${openresty}" >${Setup_Path}/version_check.pl
else
echo "${nginxVersion}" >${Setup_Path}/version.pl
fi
if [ "${GMSSL}" ]; then
echo "1.18国密版" >${Setup_Path}/version_check.pl
fi
}
Uninstall_Nginx() {
if [ -f "/etc/init.d/nginx" ]; then
Service_Del
/etc/init.d/nginx stop
rm -f /etc/init.d/nginx
fi
[ -f "${Setup_Path}/rpm.pl" ] && yum remove bt-$(cat ${Setup_Path}/rpm.pl) -y
[ -f "${Setup_Path}/deb.pl" ] && apt-get remove bt-$(cat ${Setup_Path}/deb.pl) -y
pkill -9 nginx
rm -rf ${Setup_Path}
rm -rf /www/server/btwaf/ngx
rm -rf /www/server/btwaf/resty
rm -rf /www/server/btwaf/librestysignal.so
rm -rf /www/server/btwaf/rds
rm -rf /www/server/btwaf/redis
rm -rf /www/server/btwaf/tablepool.lua
}
actionType=$1
version=$2
if [ "${actionType}" == "uninstall" ]; then
Service_Del
Uninstall_Nginx
else
case "${version}" in
'1.10')
nginxVersion=${nginx_112}
;;
'1.12')
nginxVersion=${nginx_112}
;;
'1.14')
nginxVersion=${nginx_114}
;;
'1.15')
nginxVersion=${nginx_115}
;;
'1.16')
nginxVersion=${nginx_116}
;;
'1.17')
nginxVersion=${nginx_117}
;;
'1.18')
nginxVersion=${nginx_118}
;;
'1.18.gmssl')
nginxVersion=${nginx_118}
GMSSL="True"
;;
'1.19')
nginxVersion=${nginx_119}
;;
'1.20')
nginxVersion=${nginx_120}
;;
'1.21')
nginxVersion=${nginx_121}
;;
'1.22')
nginxVersion=${nginx_122}
;;
'1.23')
nginxVersion=${nginx_123}
;;
'1.24')
nginxVersion=${nginx_124}
;;
'1.25')
nginxVersion=${nginx_125}
;;
'1.26')
nginxVersion=${nginx_126}
;;
'1.8')
nginxVersion=${nginx_108}
;;
'openresty')
nginxVersion=${openresty}
;;
*)
nginxVersion=${tengine}
version="tengine"
;;
esac
if [ "${actionType}" == "install" ]; then
if [ -f "/www/server/nginx/sbin/nginx" ]; then
Uninstall_Nginx
fi
System_Lib
if [ -z "${ARM_CHECK}" ]; then
Install_Jemalloc
Install_LuaJIT
Install_cjson
fi
Download_Src
Install_Configure
Install_Nginx
Set_Conf
Set_Version
Service_Add
/etc/init.d/nginx start
elif [ "${actionType}" == "update" ]; then
if [ "${version}" == "1.25" ];then
Install_LuaJIT
fi
Download_Src
Install_Configure
Update_Nginx
fi
fi