-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
nginx-build.sh
executable file
·1065 lines (918 loc) · 34.2 KB
/
nginx-build.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
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
# -------------------------------------------------------------------------
# Nginx-ee - Automated Nginx compilation from source
# -------------------------------------------------------------------------
# Website: https://virtubox.net
# GitHub: https://github.com/VirtuBox/nginx-ee
# Copyright (c) 2019-2024 VirtuBox <[email protected]>
# This script is licensed under M.I.T
# -------------------------------------------------------------------------
# Version 3.8.1 - 2024-04-24
# -------------------------------------------------------------------------
##################################
# Check requirements
##################################
# Check if user is root
[ "$(id -u)" != "0" ] && {
echo "Error: You must be root or use sudo to run this script"
exit 1
}
_help() {
echo " -------------------------------------------------------------------- "
echo " Nginx-ee : automated Nginx compilation with additional modules "
echo " -------------------------------------------------------------------- "
echo ""
echo "Usage: ./nginx-ee <options> [modules]"
echo "By default, Nginx-ee will compile the latest Nginx mainline release without Naxsi or RTMP module"
echo " Options:"
echo " -h, --help ..... display this help"
echo " -i, --interactive ....... interactive installation"
echo " --stable ..... Nginx stable release"
echo " --full ..... Nginx with Nasxi and RTMP module"
echo " --dynamic ..... Compile Nginx modules as dynamic"
echo " --noconf ..... Compile Nginx without any configuring. Useful when you use devops tools like ansible."
echo " Modules:"
echo " --naxsi ..... Naxsi WAF module"
echo " --rtmp ..... RTMP video streaming module"
echo " --libressl ..... Compile Nginx with LibreSSL"
echo ""
return 0
}
##################################
# Use config.inc if available
##################################
if [ -f ./config.inc ]; then
. ./config.inc
else
##################################
# Parse script arguments
##################################
while [ "$#" -gt 0 ]; do
case "$1" in
--full)
NAXSI="y"
RTMP="y"
;;
--noconf)
NOCONF="y"
;;
--naxsi)
NAXSI="y"
;;
--libressl)
LIBRESSL="y"
;;
--rtmp)
RTMP="y"
;;
--latest | --mainline)
NGINX_RELEASE="1"
;;
--stable)
NGINX_RELEASE="2"
;;
-i | --interactive)
INTERACTIVE_SETUP="1"
;;
--dynamic)
DYNAMIC_MODULES="y"
;;
--cron | --cronjob)
CRON_SETUP="y"
;;
--travis)
TRAVIS_BUILD="1"
;;
-h | --help)
_help
exit 1
;;
*) ;;
esac
shift
done
fi
export DEBIAN_FRONTEND=noninteractive
# check if a command exist
command_exists() {
command -v "$@" >/dev/null 2>&1
}
# updating packages list
[ -z "$TRAVIS_BUILD" ] && {
if [ -f "/etc/apt/sources.list.d/nginx-ee.list" ]; then
rm /etc/apt/sources.list.d/nginx-ee.list -f
fi
apt-get update -qq
}
# check if required packages are installed
required_packages="curl tar jq"
for package in $required_packages; do
if ! command_exists "$package"; then
apt-get install "$package" -qq >/dev/null 2>&1
fi
done
# Checking if lsb_release is installed
if ! command_exists lsb_release; then
apt-get -qq install lsb-release >/dev/null 2>&1
fi
##################################
# Variables
##################################
DIR_SRC="/usr/local/src"
NGINX_EE_VER=$(curl -m 5 --retry 3 -sL https://api.github.com/repos/VirtuBox/nginx-ee/releases/latest 2>&1 | jq -r '.tag_name')
NGINX_MAINLINE="$(curl -sL https://nginx.org/en/download.html 2>&1 | grep -E -o 'nginx\-[0-9.]+\.tar[.a-z]*' | awk -F "nginx-" '/.tar.gz$/ {print $2}' | sed -e 's|.tar.gz||g' | head -n 1 2>&1)"
NGINX_STABLE="$(curl -sL https://nginx.org/en/download.html 2>&1 | grep -E -o 'nginx\-[0-9.]+\.tar[.a-z]*' | awk -F "nginx-" '/.tar.gz$/ {print $2}' | sed -e 's|.tar.gz||g' | head -n 2 | grep 1.26 2>&1)"
LIBRESSL_VER="$(curl https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/ 2>&1 | grep -E -o 'libressl\-[0-9.]+\.tar[.a-z]*' | awk -F "libressl-" '/.tar.gz$/ {print $2}' | sed -e 's|.tar.gz||g' | sort -r | head -n 1)"
if command_exists openssl; then
OPENSSL_BIN_VER=$(openssl version)
OPENSSL_VER=${OPENSSL_BIN_VER:0:15}
else
OPENSSL_VER="From system"
fi
TLS13_CIPHERS="TLS13+AESGCM+AES256:TLS13+AESGCM+AES128:TLS13+CHACHA20:EECDH+CHACHA20:EECDH+AESGCM:EECDH+AES"
readonly OS_ARCH="$(uname -m)"
OS_DISTRO_FULL="$(lsb_release -ds)"
readonly DISTRO_ID="$(lsb_release -si)"
DISTRO_CODENAME="$(lsb_release -sc)"
# Colors
CSI='\033['
CRED="${CSI}1;31m"
CGREEN="${CSI}1;32m"
CEND="${CSI}0m"
##################################
# Initial check & cleanup
##################################
# clean previous install log
echo "" >/tmp/nginx-ee.log
# detect Plesk
[ -d /etc/psa ] && {
PLESK_VALID="YES"
}
# detect easyengine
[ -f /var/lib/ee/ee.db ] && {
EE_VALID="YES"
}
[ -f /var/lib/wo/dbase.db ] && {
WO_VALID="YES"
}
[ -z "$(command -v nginx)" ] && {
NGINX_FROM_SCRATCH="1"
}
##################################
# Installation menu
##################################
echo ""
echo "Welcome to the nginx-ee bash script ${NGINX_EE_VER}"
echo ""
# interactive
if [ "$INTERACTIVE_SETUP" = "1" ]; then
clear
echo ""
echo "Do you want to compile the latest Nginx [1] Mainline v${NGINX_MAINLINE} or [2] Stable v${NGINX_STABLE} Release ?"
while [[ "$NGINX_RELEASE" != "1" && "$NGINX_RELEASE" != "2" ]]; do
echo -e "Select an option [1-2]: " && read -r NGINX_RELEASE
done
echo -e '\nDo you prefer to compile Nginx with OpenSSL [1] or LibreSSL [2] ? (y/n)'
echo -e ' [1] OpenSSL'
echo -e ' [2] LibreSSL\n'
while [[ "$SSL_LIB_CHOICE" != "1" && "$SSL_LIB_CHOICE" != "2" ]]; do
echo -e "Select an option [1-2]: " && read -r SSL_LIB_CHOICE
done
if [ "$SSL_LIB_CHOICE" = "2" ]; then
LIBRESSL="y"
fi
echo -e '\nDo you want NAXSI WAF (still experimental)? (y/n)'
while [[ "$NAXSI" != "y" && "$NAXSI" != "n" ]]; do
echo -e "Select an option [y/n]: " && read -r NAXSI
done
echo -e '\nDo you want RTMP streaming module (used for video streaming) ? (y/n)'
while [[ "$RTMP" != "y" && "$RTMP" != "n" ]]; do
echo -e "Select an option [y/n]: " && read -r RTMP
done
echo -e '\nDo you want to build modules as dynamic modules? (y/n)'
while [[ "$DYNAMIC_MODULES" != "y" && "$DYNAMIC_MODULES" != "n" ]]; do
echo -e "Select an option [y/n]: " && read -r DYNAMIC_MODULES
done
echo -e '\nDo you want to setup nginx-ee auto-update cronjob ? (y/n)'
while [[ "$CRON_SETUP" != "y" && "$CRON_SETUP" != "n" ]]; do
echo -e "Select an option [y/n]: " && read -r CRON_SETUP
done
echo ""
fi
##################################
# Set nginx release and HPACK
##################################
if [ "$NGINX_RELEASE" = "2" ]; then
NGINX_VER="$NGINX_STABLE"
NGX_QUIC="--with-http_v3_module"
else
NGINX_VER="$NGINX_MAINLINE"
NGX_QUIC="--with-http_v3_module"
fi
##################################
# Set RTMP module
##################################
if [ "$RTMP" = "y" ]; then
NGX_RTMP="--add-module=../nginx-rtmp-module "
RTMP_VALID="YES"
else
NGX_RTMP=""
RTMP_VALID="NO"
fi
##################################
# Set Naxsi module
##################################
if [ "$NAXSI" = "y" ]; then
NGX_NAXSI="--add-module=../naxsi/naxsi_src "
NAXSI_VALID="YES"
else
NGX_NAXSI=""
NAXSI_VALID="NO"
fi
##################################
# Set OPENSSL/LIBRESSL lib
##################################
if [ "$LIBRESSL" = "y" ]; then
NGX_SSL_LIB="--with-openssl=../libressl"
LIBRESSL_VALID="YES"
OPENSSL_OPT=""
else
if [ "$OS_ARCH" = 'x86_64' ]; then
if [ "$DISTRO_ID" = "Ubuntu" ]; then
OPENSSL_OPT="enable-ec_nistp_64_gcc_128 enable-tls1_3 no-ssl3-method -march=native -ljemalloc"
else
OPENSSL_OPT="enable-tls1_3"
fi
fi
NGX_SSL_LIB=""
OPENSSL_VALID="from system"
if [ "$TRAVIS_BUILD" != "1" ]; then
LIBSSL_DEV="libssl-dev"
fi
fi
##################################
# Set Plesk configuration
##################################
if [ "$PLESK_VALID" = "YES" ]; then
NGX_USER="--user=nginx --group=nginx"
else
NGX_USER=""
fi
if [ "$DYNAMIC_MODULES" = "y" ]; then
DYNAMIC_MODULES_VALID="YES"
else
DYNAMIC_MODULES_VALID="NO"
fi
##################################
# Display Compilation Summary
##################################
echo ""
echo -e "${CGREEN}##################################${CEND}"
echo " Compilation summary "
echo -e "${CGREEN}##################################${CEND}"
echo ""
echo " Detected OS : $OS_DISTRO_FULL"
echo " Detected Arch : $OS_ARCH"
echo ""
echo -e " - Nginx release : $NGINX_VER"
[ -n "$OPENSSL_VALID" ] && {
echo -e " - OPENSSL : $OPENSSL_VER"
echo -e " - with HTTP/3 : YES"
}
[ -n "$LIBRESSL_VALID" ] && {
echo -e " - LIBRESSL : $LIBRESSL_VALID"
echo -e " - HTTP/3 QUIC : YES"
}
echo " - Dynamic modules $DYNAMIC_MODULES_VALID"
echo " - Naxsi : $NAXSI_VALID"
echo " - RTMP : $RTMP_VALID"
[ -n "$EE_VALID" ] && {
echo " - EasyEngine : $EE_VALID"
}
[ -n "$WO_VALID" ] && {
echo " - WordOps : $WO_VALID"
}
[ -n "$PLESK_VALID" ] && {
echo " - Plesk : $PLESK_VALID"
}
echo ""
##################################
# Install dependencies
##################################
_gitget() {
REPO="$1"
repodir=$(echo "$REPO" | awk -F "/" '{print $2}')
if [ -d "/usr/local/src/${repodir}/.git" ]; then
git -C "/usr/local/src/${repodir}" pull &
else
if [ -d "/usr/local/src/${repodir}" ]; then
rm -rf "/usr/local/src/${repodir}"
fi
git clone --depth 1 "https://github.com/${REPO}.git" "/usr/local/src/${repodir}" &
fi
}
_install_dependencies() {
echo -ne ' Installing dependencies [..]\r'
if {
apt-get -o Dpkg::Options::="--force-confmiss" -o Dpkg::Options::="--force-confold" -y install \
git build-essential libtool automake autoconf \
libgd-dev dpkg-dev libgeoip-dev libjemalloc-dev \
libbz2-1.0 libreadline-dev libbz2-dev libbz2-ocaml libbz2-ocaml-dev software-properties-common tar \
libgoogle-perftools-dev perl libperl-dev libpam0g-dev libbsd-dev gnupg gnupg2 \
libgmp-dev autotools-dev libxml2-dev libpcre3-dev uuid-dev libbrotli-dev libpcre2-dev "$LIBSSL_DEV"
} >>/tmp/nginx-ee.log 2>&1; then
echo -ne " Installing dependencies [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Installing dependencies [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Setup Nginx from scratch
##################################
_nginx_from_scratch_setup() {
echo -ne ' Setting Up Nginx configurations [..]\r'
if {
# clone custom nginx configuration
[ ! -d /etc/nginx ] && {
git clone --depth 50 https://github.com/VirtuBox/nginx-config.git /etc/nginx
} >>/tmp/nginx-ee.log 2>&1
# create nginx temp directory
mkdir -p /var/lib/nginx/{body,fastcgi,proxy,scgi,uwsgi}
# create nginx cache directory
[ ! -d /var/cache/nginx ] && {
mkdir -p /var/cache/nginx
}
[ ! -d /var/run/nginx-cache ] && {
mkdir -p /var/run/nginx-cache
}
[ ! -d /var/log/nginx ] && {
mkdir -p /var/log/nginx
chmod 640 /var/log/nginx
chown -R www-data:adm /var/log/nginx
}
# set proper permissions
chown -R www-data:root /var/lib/nginx /var/cache/nginx /var/run/nginx-cache
# create websites directory
[ ! -d /var/www/html ] && {
mkdir -p /var/www/html
}
{
# download default nginx page
wget -O /var/www/html/index.nginx-debian.html https://raw.githubusercontent.com/VirtuBox/nginx-ee/master/var/www/html/index.nginx-debian.html
mkdir -p /etc/nginx/sites-enabled
ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/
# download nginx systemd service
[ ! -f /lib/systemd/system/nginx.service ] && {
wget -O /lib/systemd/system/nginx.service https://raw.githubusercontent.com/VirtuBox/nginx-ee/master/etc/systemd/system/nginx.service
systemctl enable nginx.service
}
# download logrotate configuration
wget -O /etc/logrotate.d/nginx https://raw.githubusercontent.com/VirtuBox/nginx-ee/master/etc/logrotate.d/nginx
} >>/tmp/nginx-ee.log 2>&1
}; then
echo -ne " Setting Up Nginx configurations [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Setting Up Nginx configurations [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Dynamic modules
##################################
_dynamic_setup() {
if [ -d /usr/share/nginx/modules ]; then
rm -rf /usr/share/nginx/modules/*.old
mkdir -p /etc/nginx/{modules.available.d,modules.conf.d}
rm -rf /etc/nginx/modules.conf.d/*
modules_list=$(basename -a /usr/share/nginx/modules/*)
for module in $modules_list; do
echo "load_module /usr/share/nginx/modules/${module};" >"/etc/nginx/modules.available.d/${module%.so}.load"
ln -s "/etc/nginx/modules.available.d/${module%.so}.load" "/etc/nginx/modules.conf.d/${module%.so}.conf"
done
fi
}
##################################
# Install gcc
##################################
_gcc_setup() {
echo -ne ' Installing gcc [..]\r'
if {
echo "### installing gcc ###"
apt-get install gcc g++ -y
} >>/dev/null 2>&1; then
echo -ne " Installing gcc [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Installing gcc [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Install ffmpeg for rtmp module
##################################
_rtmp_setup() {
echo -ne ' Installing FFMPEG for RTMP module [..]\r'
if {
apt-get install ffmpeg -y
} >>/dev/null 2>&1; then
echo -ne " Installing FFMPEG for RMTP module [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Installing FFMPEG for RMTP module [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Cleanup modules
##################################
_cleanup_modules() {
cd "$DIR_SRC" || exit 1
rm -rf /usr/local/src/{*.tar.gz,nginx,nginx-1.*,pcre,zlib,incubator-pagespeed-*,build_ngx_pagespeed.sh,install,ngx_http_redis,naxsi}
}
##################################
# Download additional modules
##################################
_download_modules() {
echo -ne ' Downloading additionals modules [..]\r'
if {
echo "### downloading additionals modules ###"
MODULES='openresty/memc-nginx-module
simpl/ngx_devel_kit openresty/headers-more-nginx-module
openresty/echo-nginx-module yaoweibin/ngx_http_substitutions_filter_module
openresty/redis2-nginx-module openresty/srcache-nginx-module
openresty/set-misc-nginx-module sto/ngx_http_auth_pam_module
vozlt/nginx-module-vts centminmod/ngx_http_redis nginx-modules/ngx_cache_purge'
for MODULE in $MODULES; do
_gitget "$MODULE"
done
if [ "$RTMP" = "y" ]; then
{ [ -d "$DIR_SRC/nginx-rtmp-module" ] && {
git -C "$DIR_SRC/nginx-rtmp-module" pull &
} } || {
git clone --depth=1 https://github.com/arut/nginx-rtmp-module.git &
}
fi
# ipscrub module
{ [ -d "$DIR_SRC/ipscrubtmp" ] && {
git -C "$DIR_SRC/ipscrubtmp" pull origin master &
} } || {
git clone --depth=1 https://github.com/masonicboom/ipscrub.git ipscrubtmp &
}
wait
echo "### additionals modules downloaded ###"
} >>/tmp/nginx-ee.log 2>&1; then
echo -ne " Downloading additionals modules [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Downloading additionals modules [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Download zlib
##################################
_download_zlib() {
echo -ne ' Downloading zlib [..]\r'
if {
cd "$DIR_SRC" || exit 1
if [ "$OS_ARCH" = 'x86_64' ]; then
{ [ -d /usr/local/src/zlib-cf ] && {
echo "### git pull zlib-cf ###"
git -c /usr/local/src/zlib-cf pull
}; } || {
echo "### cloning zlib-cf ###"
git clone --depth=1 https://github.com/cloudflare/zlib.git -b gcc.amd64 /usr/local/src/zlib-cf
}
cd /usr/local/src/zlib-cf || exit 1
echo "### make distclean ###"
make -f Makefile.in distclean
echo "### configure zlib-cf ###"
./configure --prefix=/usr/local/zlib-cf
else
echo "### downloading zlib latest ###"
rm -rf zlib*
curl -sL http://zlib.net/current/zlib.tar.gz | /bin/tar zxf - -C "$DIR_SRC"
mv zlib* zlib
fi
} >>/tmp/nginx-ee.log 2>&1; then
echo -ne " Downloading zlib [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Downloading zlib [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Download ngx_broti
##################################
_download_brotli() {
cd "$DIR_SRC" || exit 1
if {
echo -ne ' Downloading brotli [..]\r'
{
rm /usr/local/src/ngx_brotli -rf
git clone --recursive --depth=1 https://github.com/google/ngx_brotli /usr/local/src/ngx_brotli -q
cd /usr/local/src/ngx_brotli || exit 1
git submodule update --init
} >>/tmp/nginx-ee.log 2>&1
}; then
echo -ne " Downloading brotli [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Downloading brotli [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Download LibreSSL
##################################
_download_libressl() {
cd "$DIR_SRC" || exit 1
if {
echo -ne ' Downloading LibreSSL [..]\r'
{
rm -rf /usr/local/src/libressl
curl -sL "http://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-$LIBRESSL_VER.tar.gz" | /bin/tar xzf - -C "$DIR_SRC"
mv "/usr/local/src/libressl-$LIBRESSL_VER" /usr/local/src/libressl
} >>/tmp/nginx-ee.log 2>&1
}; then
echo -ne " Downloading LibreSSL [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Downloading LibreSSL [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Download Naxsi
##################################
_download_naxsi() {
cd "$DIR_SRC" || exit 1
if {
echo -ne ' Downloading naxsi [..]\r'
{
git clone --depth=50 --recurse-submodules https://github.com/wargio/naxsi.git /usr/local/src/naxsi -q
if [ "$NOCONF" != "y" ]; then
cp -f /usr/local/src/naxsi/naxsi_rules/naxsi_core.rules /etc/nginx/naxsi_core.rules
fi
} >>/tmp/nginx-ee.log 2>&1
}; then
echo -ne " Downloading naxsi [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Downloading naxsi [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Download Nginx
##################################
_download_nginx() {
cd "$DIR_SRC" || exit 1
if {
echo -ne ' Downloading nginx [..]\r'
{
rm -rf /usr/local/src/nginx
curl -sL "http://nginx.org/download/nginx-${NGINX_VER}.tar.gz" | /bin/tar xzf - -C "$DIR_SRC"
mv "/usr/local/src/nginx-${NGINX_VER}" /usr/local/src/nginx
} >>/tmp/nginx-ee.log 2>&1
}; then
echo -ne " Downloading nginx [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Downloading nginx [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Apply Nginx patches
##################################
_patch_nginx() {
cd /usr/local/src/nginx || exit 1
if {
echo -ne ' Applying nginx patches [..]\r'
{
curl -sL https://raw.githubusercontent.com/kn007/patch/master/nginx_dynamic_tls_records.patch | patch -p1
} >>/tmp/nginx-ee.log 2>&1
}; then
echo -ne " Applying nginx patches [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Applying nginx patches [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Configure Nginx
##################################
_configure_nginx() {
local DEB_CFLAGS
local DEB_LFLAGS
DEB_CFLAGS="$(dpkg-buildflags --get CPPFLAGS) -Wno-error=date-time"
DEB_LFLAGS="$(dpkg-buildflags --get LDFLAGS)"
if {
echo -ne ' Configuring nginx build [..]\r'
# main configuration
NGINX_BUILD_OPTIONS="--prefix=/usr/share \
--conf-path=/etc/nginx/nginx.conf \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log \
--lock-path=/var/lock/nginx.lock \
--pid-path=/var/run/nginx.pid \
--http-client-body-temp-path=/var/lib/nginx/body \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--modules-path=/usr/share/nginx/modules"
# built-in modules
if [ -z "$OVERRIDE_NGINX_MODULES" ]; then
NGINX_INCLUDED_MODULES="--with-http_stub_status_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-http_addition_module \
--with-http_gzip_static_module \
--with-http_gunzip_module \
--with-http_mp4_module \
--with-http_sub_module"
else
NGINX_INCLUDED_MODULES="$OVERRIDE_NGINX_MODULES"
fi
# third party modules
if [ -z "$OVERRIDE_NGINX_ADDITIONAL_MODULES" ]; then
if [ "$DYNAMIC_MODULES" = "y" ]; then
NGINX_THIRD_MODULES="--with-compat \
--add-module=../ngx_http_substitutions_filter_module \
--add-dynamic-module=../srcache-nginx-module \
--add-dynamic-module=../redis2-nginx-module \
--add-dynamic-module=../memc-nginx-module \
--add-module=../ngx_devel_kit \
--add-module=../ngx_http_redis \
--add-module=../set-misc-nginx-module \
--add-dynamic-module=../ngx_http_auth_pam_module \
--add-module=../nginx-module-vts \
--add-dynamic-module=../ipscrubtmp/ipscrub"
else
NGINX_THIRD_MODULES="--add-module=../ngx_http_substitutions_filter_module \
--add-module=../srcache-nginx-module \
--add-module=../redis2-nginx-module \
--add-module=../ngx_http_redis \
--add-module=../memc-nginx-module \
--add-module=../ngx_devel_kit \
--add-module=../set-misc-nginx-module \
--add-module=../ngx_http_auth_pam_module \
--add-module=../nginx-module-vts \
--add-module=../ipscrubtmp/ipscrub"
fi
else
NGINX_THIRD_MODULES="$OVERRIDE_NGINX_ADDITIONAL_MODULES"
fi
if [ "$OS_ARCH" = 'x86_64' ]; then
if [ "$DISTRO_ID" = "Ubuntu" ] && [ "$DISTRO_CODENAME" != "noble" ]; then
DEB_CFLAGS='-m64 -march=native -mtune=native -DTCP_FASTOPEN=23 -g -O3 -fstack-protector-strong -flto -ffat-lto-objects -fuse-ld=gold --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wimplicit-fallthrough=0 -fcode-hoisting -Wp,-D_FORTIFY_SOURCE=2 -gsplit-dwarf'
DEB_LFLAGS='-lrt -ljemalloc -Wl,-z,relro -Wl,-z,now -fPIC -flto -ffat-lto-objects'
fi
ZLIB_PATH='../zlib-cf'
else
ZLIB_PATH='../zlib'
fi
bash -c "./configure \
${NGX_NAXSI} \
--with-cc-opt='$DEB_CFLAGS' \
--with-ld-opt='$DEB_LFLAGS' \
$NGINX_BUILD_OPTIONS \
--build='VirtuBox Nginx-ee' \
$NGX_USER \
--with-file-aio \
--with-threads \
$NGX_QUIC \
--with-http_v2_module \
--with-http_ssl_module \
--with-pcre-jit \
$NGINX_INCLUDED_MODULES \
$NGINX_THIRD_MODULES \
$NGX_RTMP \
--add-module=../echo-nginx-module \
--add-module=../headers-more-nginx-module \
--add-module=../ngx_cache_purge \
--add-module=../ngx_brotli \
--with-zlib=$ZLIB_PATH \
$NGX_SSL_LIB \
--with-openssl-opt='$OPENSSL_OPT' \
--sbin-path=/usr/sbin/nginx >> /tmp/nginx-ee.log 2>&1;"
}; then
echo -ne " Configuring nginx build [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Configuring nginx build [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Compile Nginx
##################################
_compile_nginx() {
if {
echo -ne ' Compiling nginx [..]\r'
{
# compile Nginx
make -j "$(nproc)"
# Strip debug symbols
strip --strip-unneeded /usr/local/src/nginx/objs/nginx
if [ "$DYNAMIC_MODULES" = "y" ]; then
strip --strip-unneeded /usr/local/src/nginx/objs/*.so
fi
# install Nginx
make install
} >>/tmp/nginx-ee.log 2>&1
}; then
echo -ne " Compiling nginx [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Compiling nginx [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
##################################
# Perform final tasks
##################################
_updating_nginx_manual() {
echo -ne ' Updating Nginx manual [..]\r'
if {
# update nginx manual
[ -f /usr/share/man/man8/nginx.8.gz ] && {
rm /usr/share/man/man8/nginx.8.gz
}
{
cp -f ${DIR_SRC}/nginx/man/nginx.8 /usr/share/man/man8
gzip /usr/share/man/man8/nginx.8
} >>/tmp/nginx-ee.log
# update mime.types
cp -f ${DIR_SRC}/nginx/conf/mime.types /etc/nginx/mime.types
}; then
echo -ne " Updating Nginx manual [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Updating Nginx manual [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
_cron_setup() {
echo -ne ' Installing Nginx-ee Cronjob [..]\r'
if {
wget -O /etc/cron.daily/nginx-ee https://raw.githubusercontent.com/VirtuBox/nginx-ee/develop/etc/cron.daily/nginx-ee >>/tmp/nginx-ee.log
chmod +x /etc/cron.daily/nginx-ee
}; then
echo -ne " Installing Nginx-ee Cronjob [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Installing Nginx-ee Cronjob [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
}
_cron_update() {
if [ -f /etc/cron.daily/nginx-ee ]; then
wget -O /etc/cron.daily/nginx-ee https://raw.githubusercontent.com/VirtuBox/nginx-ee/develop/etc/cron.daily/nginx-ee >>/tmp/nginx-ee.log
chmod +x /etc/cron.daily/nginx-ee
fi
}
_final_tasks() {
echo -ne ' Performing final steps [..]\r'
if {
# block Nginx package update from APT repository
if [ "$PLESK_VALID" = "YES" ]; then
{
# update nginx ciphers_suites
# sed -i "s/ssl_ciphers\ \(\"\|.\|'\)\(.*\)\(\"\|.\|'\);/ssl_ciphers \"$TLS13_CIPHERS\";/" /etc/nginx/conf.d/ssl.conf
# update nginx ssl_protocols
# sed -i "s/ssl_protocols\ \(.*\);/ssl_protocols TLSv1.2 TLSv1.3;/" /etc/nginx/conf.d/ssl.conf
# block sw-nginx package updates from APT repository
echo -e 'Package: sw-nginx*\nPin: release *\nPin-Priority: -1' >/etc/apt/preferences.d/nginx-block
apt-mark hold sw-nginx
} >>/tmp/nginx-ee.log
elif [ "$EE_VALID" = "YES" ]; then
{
# update nginx ssl_protocols
sed -i "s/ssl_protocols\ \(.*\);/ssl_protocols TLSv1.2 TLSv1.3;/" /etc/nginx/nginx.conf
# update nginx ciphers_suites
sed -i "s/ssl_ciphers\ \(\"\|'\)\(.*\)\(\"\|'\)/ssl_ciphers \"$TLS13_CIPHERS\"/" /etc/nginx/nginx.conf
# block nginx package updates from APT repository
echo -e 'Package: nginx*\nPin: release *\nPin-Priority: -1' >/etc/apt/preferences.d/nginx-block
apt-mark hold nginx-ee nginx-common nginx-custom
} >>/tmp/nginx-ee.log
elif [ "$WO_VALID" = "YES" ]; then
{
# update nginx ssl_protocols
# sed -i "s/ssl_protocols\ \(.*\);/ssl_protocols TLSv1.2 TLSv1.3;/" /etc/nginx/nginx.conf
# update nginx ciphers_suites
# sed -i "s/ssl_ciphers\ \(\"\|.\|'\)\(.*\)\(\"\|.\|'\);/ssl_ciphers \"$TLS13_CIPHERS\";/" /etc/nginx/nginx.conf
# block nginx package updates from APT repository
echo -e 'Package: nginx*\nPin: release *\nPin-Priority: -1' >/etc/apt/preferences.d/nginx-block
CHECK_NGINX_WO=$(dpkg --list | grep nginx-wo)
if [ -n "$CHECK_NGINX_WO" ]; then
apt-mark hold nginx-wo nginx-common nginx-custom
else
apt-mark hold nginx-ee nginx-common nginx-custom
fi
} >>/tmp/nginx-ee.log 2>&1
fi
if [ "$NOCONF" != "y" ]; then
{
# enable nginx service
systemctl unmask nginx.service
systemctl enable nginx.service
systemctl start nginx.service
# remove default configuration
rm -f /etc/nginx/{*.default,*.dpkg-dist}
} >/dev/null 2>&1
fi
}; then
echo -ne " Performing final steps [${CGREEN}OK${CEND}]\\r"
echo -ne '\n'
else
echo -e " Performing final steps [${CRED}FAIL${CEND}]"
echo -e '\n Please look at /tmp/nginx-ee.log\n'
exit 1
fi
echo -ne ' Checking nginx configuration [..]\r'
if [ "$NOCONF" != "y" ]; then