/
nginx_upgrade.inc
1107 lines (965 loc) · 46.3 KB
/
nginx_upgrade.inc
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
check_requestscheme() {
# check for REQUEST_SCHEME parameter added in nginx 1.9.2
# add it if it doesn't exist in fastcgi_param and php include files
for f in "$(grep -Rl 'fastcgi_param SERVER_PROTOCOL \$server_protocol;' /usr/local/nginx/conf/*)";
do
# only proceed with routine if the file referenced in $f variable exists
if [ -f "$f" ]; then
echo "$f"
ff=$(grep 'REQUEST_SCHEME' "$f")
fff=$(grep 'https if_not_empty' "$f")
if [[ -z "$ff" && -z "$fff" ]]; then
sed -i "s|fastcgi_param SERVER_PROTOCOL \$server_protocol;|fastcgi_param SERVER_PROTOCOL \$server_protocol;\nfastcgi_param REQUEST_SCHEME \$scheme;\nfastcgi_param HTTPS \$https if_not_empty;|" "$f"
elif [[ -z "$ff" && "$fff" ]]; then
sed -i "s|fastcgi_param SERVER_PROTOCOL \$server_protocol;|fastcgi_param SERVER_PROTOCOL \$server_protocol;\nfastcgi_param REQUEST_SCHEME \$scheme;|" "$f"
fi
fi
done
## DOES NOT WORK due to invalid version comparison for 2 dot
## numbers i.e. 2.0.0 < 1.9.1 would return false
# # check for REQUEST_SCHEME parameter added in nginx 1.9.2
# # if nginx upgrade or downgrade is less than 1.9.2 comment out
# # REQUEST_SCHEME, if greater or equal to 1.9.2 uncomment
# for f in $(grep -Rl 'REQUEST_SCHEME' /usr/local/nginx/conf/*);
# do
# echo "$f"
# if [[ "$(expr $ngver \<= 1.9.1)" = 1 ]]; then
# sed -i "s|fastcgi_param REQUEST_SCHEME|#fastcgi_param REQUEST_SCHEME|" $f
# elif [[ "$(expr $ngver \>= 1.9.2)" = 1 ]]; then
# sed -i "s|#fastcgi_param REQUEST_SCHEME|fastcgi_param REQUEST_SCHEME|" $f
# fi
# done
}
checkgeoip() {
GEOIP_CHECK=$(nginx -V 2>&1 | grep geoip)
if [[ ! -z "$GEOIP_CHECK" && "$(grep 'NGINX_GEOIP=n' "${SCRIPT_DIR}/centmin.sh")" ]]; then
cecho "Detected existing Nginx has NGINX_GEOIP=y enabled" $boldyellow
cecho "however, you are recompiling Nginx with NGINX_GEOIP=n" $boldyellow
cecho "Is this incorrect and you want to set NGINX_GEOIP=y enabled ? " $boldyellow
read -ep "Answer y or n. Typing y will set NGINX_GEOIP=y [y/n]: " setgeoip
if [[ "$setgeoip" = [yY] ]]; then
NGINX_GEOIP=y
fi
fi
}
checkmap() {
VTSHTTP_INCLUDECHECK=$(grep '\/usr\/local\/nginx\/conf\/vts_http.conf' /usr/local/nginx/conf/nginx.conf)
VTSMAIN_INCLUDECHECK=$(grep '\/usr\/local\/nginx\/conf\/vts_mainserver.conf' /usr/local/nginx/conf/conf.d/virtual.conf)
if [[ -z "$VTSHTTP_INCLUDECHECK" ]]; then
if [[ "$NGINX_VHOSTSTATS" = [yY] ]]; then
sed -i 's/http {/http { \ninclude \/usr\/local\/nginx\/conf\/vts_http.conf;/g' /usr/local/nginx/conf/nginx.conf
else
sed -i 's/http {/http { \ninclude \/usr\/local\/nginx\/conf\/vts_http.conf;/g' /usr/local/nginx/conf/nginx.conf
fi
else
if [[ "$NGINX_VHOSTSTATS" = [yY] ]]; then
if [[ "$(grep '#include \/usr\/local\/nginx\/conf\/vts_http.conf' /usr/local/nginx/conf/nginx.conf)" ]]; then
sed -i 's/#include \/usr\/local\/nginx\/conf\/vts_http.conf/include \/usr\/local\/nginx\/conf\/vts_http.conf/g' /usr/local/nginx/conf/nginx.conf
fi
if [[ "$(grep '#include \/usr\/local\/nginx\/conf\/vts_mainserver.conf' /usr/local/nginx/conf/conf.d/virtual.conf)" ]]; then
sed -i 's|#include \/usr\/local\/nginx\/conf\/vts_mainserver.conf|include \/usr\/local\/nginx\/conf\/vts_mainserver.conf|g' /usr/local/nginx/conf/conf.d/virtual.conf
fi
else
if [[ "$(grep '^include \/usr\/local\/nginx\/conf\/vts_http.conf' /usr/local/nginx/conf/nginx.conf)" ]]; then
sed -i 's/include \/usr\/local\/nginx\/conf\/vts_http.conf/#include \/usr\/local\/nginx\/conf\/vts_http.conf/g' /usr/local/nginx/conf/nginx.conf
fi
if [[ "$(grep '^include \/usr\/local\/nginx\/conf\/vts_mainserver.conf' /usr/local/nginx/conf/conf.d/virtual.conf)" ]]; then
sed -i 's|^include \/usr\/local\/nginx\/conf\/vts_mainserver.conf|#include \/usr\/local\/nginx\/conf\/vts_mainserver.conf|g' /usr/local/nginx/conf/conf.d/virtual.conf
fi
fi
fi
if [[ -z "$VTSMAIN_INCLUDECHECK" ]]; then
if [[ "$NGINX_VHOSTSTATS" = [yY] ]]; then
sed -i 's/include \/usr\/local\/nginx\/conf\/errorpage.conf;/include \/usr\/local\/nginx\/conf\/errorpage.conf; \ninclude \/usr\/local\/nginx\/conf\/vts_mainserver.conf;/g' /usr/local/nginx/conf/conf.d/virtual.conf
sed -i 's|#include \/usr\/local\/nginx\/conf\/vts_mainserver.conf|include \/usr\/local\/nginx\/conf\/vts_mainserver.conf|' /usr/local/nginx/conf/conf.d/virtual.conf
else
sed -i 's/include \/usr\/local\/nginx\/conf\/errorpage.conf;/include \/usr\/local\/nginx\/conf\/errorpage.conf; \n#include \/usr\/local\/nginx\/conf\/vts_mainserver.conf;/g' /usr/local/nginx/conf/conf.d/virtual.conf
sed -i 's|include \/usr\/local\/nginx\/conf\/vts_mainserver.conf|#include \/usr\/local\/nginx\/conf\/vts_mainserver.conf|' /usr/local/nginx/conf/conf.d/virtual.conf
fi
fi
if [[ ! -f /usr/local/nginx/conf/vts_http.conf ]]; then
\cp "$CUR_DIR/config/nginx/vts_http.conf" /usr/local/nginx/conf/vts_http.conf
fi
if [[ ! -f /usr/local/nginx/conf/vts_mainserver.conf ]]; then
\cp "$CUR_DIR/config/nginx/vts_mainserver.conf" /usr/local/nginx/conf/vts_mainserver.conf
fi
if [[ ! -f /usr/local/nginx/conf/vts_server.conf ]]; then
\cp "$CUR_DIR/config/nginx/vts_server.conf" /usr/local/nginx/conf/vts_server.conf
fi
if [[ "$NGINX_VHOSTSTATS" = [yY] ]]; then
if [[ "$(grep '^#vhost_traffic_status_zone' /usr/local/nginx/conf/vts_http.conf)" ]]; then
sed -i 's/#vhost_traffic_status_zone/vhost_traffic_status_zone/' /usr/local/nginx/conf/vts_http.conf
fi
if [[ "$(grep '^#vhost_traffic_status_dump' /usr/local/nginx/conf/vts_http.conf)" ]]; then
sed -i 's/#vhost_traffic_status_dump/vhost_traffic_status_dump/' /usr/local/nginx/conf/vts_http.conf
fi
if [[ "$(grep '^#vhost_traffic_status on' /usr/local/nginx/conf/vts_server.conf)" ]]; then
sed -i 's/#vhost_traffic_status on/vhost_traffic_status on/' /usr/local/nginx/conf/vts_server.conf
fi
else
if [[ "$(grep '^vhost_traffic_status_zone' /usr/local/nginx/conf/vts_http.conf)" ]]; then
sed -i 's/vhost_traffic_status_zone/#vhost_traffic_status_zone/' /usr/local/nginx/conf/vts_http.conf
fi
if [[ "$(grep '^vhost_traffic_status_dump' /usr/local/nginx/conf/vts_http.conf)" ]]; then
sed -i 's/vhost_traffic_status_dump/#vhost_traffic_status_dump/' /usr/local/nginx/conf/vts_http.conf
fi
if [[ "$(grep '^vhost_traffic_status on' /usr/local/nginx/conf/vts_server.conf)" ]]; then
sed -i 's/vhost_traffic_status on/#vhost_traffic_status on/' /usr/local/nginx/conf/vts_server.conf
fi
fi
MAPCHECK=$(grep '/usr/local/nginx/conf/fastcgi_param_https_map.conf' /usr/local/nginx/conf/nginx.conf)
if [[ -z "$MAPCHECK" ]]; then
sed -i 's/http {/http { \ninclude \/usr\/local\/nginx\/conf\/fastcgi_param_https_map.conf;/g' /usr/local/nginx/conf/nginx.conf
fi
if [[ ! -f /usr/local/nginx/conf/fastcgi_param_https_map.conf ]]; then
\cp "$CUR_DIR/config/nginx/fastcgi_param_https_map.conf" /usr/local/nginx/conf/fastcgi_param_https_map.conf
fi
if [[ -z "$(grep 'fastcgi_param HTTPS $server_https;' /usr/local/nginx/conf/php.conf)" ]]; then
replace -s '#fastcgi_param HTTPS on;' 'fastcgi_param HTTPS $server_https;' -- /usr/local/nginx/conf/php.conf
fi
}
checknginxmodules() {
axelsetup
if [ -f "${CM_INSTALLDIR}/inc/custom_config.inc" ]; then
source "${CM_INSTALLDIR}/inc/custom_config.inc"
fi
if [ -f "${CONFIGSCANBASE}/custom_config.inc" ]; then
# default is at /etc/centminmod/custom_config.inc
source "${CONFIGSCANBASE}/custom_config.inc"
fi
if [ -f "${CM_INSTALLDIR}/inc/z_custom.inc" ]; then
source "${CM_INSTALLDIR}/inc/z_custom.inc"
fi
if [[ "$ORESTY_LUANGINX" = [yY] ]]; then
# lua nginx 0.10.7 and lower not compatible with openssl 1.1.x branch
# so fall back to 1.0.2 branch if lua nginx module is enabled
OPENSSL_VERSION="$OPENSSL_VERSIONFALLBACK"
OPENSSL_LINKFILE="openssl-${OPENSSL_VERSION}.tar.gz"
OPENSSL_LINK="https://www.openssl.org/source/${OPENSSL_LINKFILE}"
fi
if [ -f "$(which figlet)" ]; then
figlet -ckf standard "Check Nginx Modules"
fi
#################################################################################
# detection routine to see if Nginx supports Dynamic modules from nginx 1.9.11+
echo
echo "NGX_DYNAMICCHECK nginx_upgrade.inc"
pwd
echo
echo "nginx dynamic module support detected"
echo
if [ "$ngver" ]; then
NGINX_DIRINSTALL="$DIR_TMP/nginx-${ngver}"
else
NGINX_DIRINSTALL="$DIR_TMP/nginx-${NGINX_VERSION}"
fi
NGX_DYNAMICCHECK=$(grep 'DYNAMIC_MODULES=' "$NGINX_DIRINSTALL/auto/options" >/dev/null 2>&1; echo $?)
if [ "$NGX_DYNAMICCHECK" = '0' ]; then
DYNAMIC_SUPPORT=y
else
# remove patches meant for 1.9.11 dynamic module support
rm -rf "${DIR_TMP}lua-nginx-module-${ORESTY_LUANGINXVER}"
rm -rf "${DIR_TMP}/${NGX_LUANGINXLINKFILE}"
fi
if [[ "$NGINX_RTMP" = [yY] ]]; then
if [[ ! -d "${DIR_TMP}/nginx-rtmp-module" ]]; then
echo
echo "download nginx-rtmp-module from github"
cd "$DIR_TMP"
time git clone git://github.com/arut/nginx-rtmp-module.git
elif [[ -d "${DIR_TMP}/nginx-rtmp-module" && -d "${DIR_TMP}/nginx-rtmp-module/.git" ]]; then
echo
echo "get latest updates nginx-rtmp-module from github"
cd "$DIR_TMP"
git stash
git pull
git log -3
fi
fi
cecho "Check for old ngx_pagespeed master branch existence" $boldyellow
if [[ -d "${DIR_TMP}/ngx_pagespeed-release-${NGXPGSPEED_VER}/ngx_pagespeed-master" ]]; then
# rm -rf ${DIR_TMP}/ngx_pagespeed-release-${NGXPGSPEED_VER}
rm -rf ${DIR_TMP}/ngx_pagespeed-release-*
rm -rf ${DIR_TMP}/ngx_pagespeed-*
rm -rf ${DIR_TMP}/release-1.9.32*
nginxpgspeedtarball
fi
cecho "Check for missing nginx modules" $boldyellow
LIBRESSLDIR=$(tar -tzf "$DIR_TMP/${LIBRESSL_LINKFILE}" 2>&1 | head -1 | cut -f1 -d"/" | grep libressl)
if [[ ! -f "${DIR_TMP}/${LIBRESSL_LINKFILE}" || ! -d "${DIR_TMP}/${LIBRESSLDIR}" ]]; then
libressldownload
elif [[ ! -f "${DIR_TMP}/${LIBRESSL_LINKFILE}" ]]; then
libressldownload
fi
if [[ ! -f "${DIR_TMP}/${NGX_ZLIBLINKFILE}" || ! -d "${DIR_TMP}/zlib-${NGINX_ZLIBVER}" ]]; then
nginxzlibtarball
fi
if [[ ! -f "${DIR_TMP}/${NGX_FANCYINDEXLINKFILE}" || ! -f "${DIR_TMP}/${NGX_CACHEPURGEFILE}" || ! -f "${DIR_TMP}/${NGX_ACCESSKEYLINKFILE}" || ! -f "${DIR_TMP}/${NGX_CONCATLINKFILE}" || ! -f "${DIR_TMP}/${OPENSSL_LINKFILE}" || ! -f "${DIR_TMP}/${PCRELINKFILE}" || ! -f "${DIR_TMP}/${NGX_WEBDAVLINKFILE}" || ! -f "${DIR_TMP}/${NGX_HEADERSMORELINKFILE}" || ! -f "${DIR_TMP}/${NGX_STICKYLINKFILE}" || ! -f "${DIR_TMP}/${NGX_UPSTREAMCHECKLINKFILE}" || ! -f "${DIR_TMP}/${NGX_HTTPREDISLINKFILE}" ]] || [[ ! -d "${DIR_TMP}/${NGX_FANCYINDEXDIR}" || ! -d "${DIR_TMP}/${NGX_CACHEPURGEDIR}" || ! -d "${DIR_TMP}/nginx-accesskey-2.0.3" || ! -d "${DIR_TMP}/${NGX_CONCATDIR}" || ! -d "${DIR_TMP}/${OPENSSLDIR}" || ! -d "${DIR_TMP}/${PCRELINKDIR}" || ! -d "${DIR_TMP}/${NGX_WEBDAVLINKDIR}" || ! -d "${DIR_TMP}/${NGX_HEADERSMOREDIR}" || ! -d "${DIR_TMP}/${NGX_STICKYDIR}" || ! -d "${DIR_TMP}/${NGX_UPSTREAMCHECKDIR}" || ! -d "${DIR_TMP}/${NGX_HTTPREDISDIR}" ]]; then
if [[ "$PARALLEL_MODE" = [yY] ]] && [[ "$(grep "processor" /proc/cpuinfo |wc -l)" -gt '1' ]]; then
ngxmoduletarball &
if [[ "$LIBRESSL_SWITCH" = 'n' ]]; then
openssldownload &
fi
# libressldownload &
wait
else
ngxmoduletarball
if [[ "$LIBRESSL_SWITCH" = 'n' ]]; then
openssldownload
fi
# libressldownload
fi
fi
cecho "Check for pagespeed nginx module download file" $boldyellow
# echo "${DIR_TMP}/${NGX_PAGESPEEDGITLINKFILE}"
# echo "$DIR_TMP/$LIBUNWIND_LINKDIR"
NGXPGSPEED_DIR=$(tar -tzf "$DIR_TMP/${NGX_PAGESPEEDLINKFILE}" 2>1 | head -1 | cut -f1 -d"/")
if [[ ! -f "${DIR_TMP}/${NGX_PAGESPEEDGITLINKFILE}" || ! -d "$DIR_TMP/$NGXPGSPEED_DIR" ]]; then
if [[ "$NGINX_PAGESPEED" = [yY] ]]; then
nginxpgspeedtarball
# determine top level extracted directory name for $DIR_TMP/${NGX_PAGESPEEDLINKFILE}
NGXPGSPEED_DIR=$(tar -tzf "$DIR_TMP/${NGX_PAGESPEEDLINKFILE}" | head -1 | cut -f1 -d"/")
fi
elif [[ ! -f "${DIR_TMP}/${NGX_PAGESPEEDGITLINKFILE}" ]]; then
if [[ "$NGINX_PAGESPEED" = [yY] ]]; then
nginxpgspeedtarball
# determine top level extracted directory name for $DIR_TMP/${NGX_PAGESPEEDLINKFILE}
NGXPGSPEED_DIR=$(tar -tzf "$DIR_TMP/${NGX_PAGESPEEDLINKFILE}" | head -1 | cut -f1 -d"/")
fi
else
if [[ "$NGINX_PAGESPEED" = [yY] ]]; then
# determine top level extracted directory name for $DIR_TMP/${NGX_PAGESPEEDLINKFILE}
NGXPGSPEED_DIR=$(tar -tzf "$DIR_TMP/${NGX_PAGESPEEDLINKFILE}" | head -1 | cut -f1 -d"/")
fi
fi
cecho "Check for pagespeed PSOL library" $boldyellow
if [ -d "$DIR_TMP/$NGXPGSPEED_DIR" ]; then
if [[ ! -f "$DIR_TMP/$NGXPGSPEED_DIR/${NGX_PAGESPEEDPSOLINKLFILE}" ]]; then
nginxpgspeedtarball
fi
fi
cecho "Check for gperf tools + libunwind download files" $boldyellow
if [[ ! -f "${DIR_TMP}/${LIBUNWIND_LINKFILE}" || ! -d "$DIR_TMP/$LIBUNWIND_LINKDIR" ]] || [[ ! -f "${DIR_TMP}/${GPERFTOOL_LINKFILE}" || ! -d "$DIR_TMP/$GPERFTOOL_LINKDIR" ]]; then
if [[ "$GPERFTOOLS_SOURCEINSTALL" = [yY] ]]; then
gperftools
fi
elif [[ ! -f "${DIR_TMP}/${LIBUNWIND_LINKFILE}" ]] || [[ ! -f "${DIR_TMP}/${GPERFTOOL_LINKFILE}" ]]; then
if [[ "$GPERFTOOLS_SOURCEINSTALL" = [yY] ]]; then
gperftools
fi
fi
if [[ "$NGINX_OPENRESTY" = [yY] ]]; then
# nginx upgrade routine needs to know directory names for specific nginx
# modules to know if they exist
cecho "Check for openresty modules" $boldyellow
# if the tar.gz files don't exist first the tar test directory variables can not be populated
if [[ ! -f "${DIR_TMP}/${NGX_MEMCLINKFILE}" || ! -f "${DIR_TMP}/${NGX_SRCACHELINKFILE}"|| ! -f "${DIR_TMP}/${NGX_REDISLINKFILE}" || ! -f "${DIR_TMP}/${NGX_ECHOLINKFILE}" || ! -f "${DIR_TMP}/${NGX_SETMISCLINKFILE}" || ! -f "${DIR_TMP}/${NGX_DEVELKITLINKFILE}" ]]; then
openrestytarball
fi
MEMCDIR=$(tar -tzf "$DIR_TMP/${NGX_MEMCLINKFILE}" | head -1 | cut -f1 -d"/")
SRCACHEDIR=$(tar -tzf "$DIR_TMP/${NGX_SRCACHELINKFILE}" | head -1 | cut -f1 -d"/")
SETMISCDIR=$(tar -tzf "$DIR_TMP/${NGX_SETMISCLINKFILE}" | head -1 | cut -f1 -d"/")
DEVELKITDIR=$(tar -tzf "$DIR_TMP/${NGX_DEVELKITLINKFILE}" | head -1 | cut -f1 -d"/")
ECHODIR=$(tar -tzf "$DIR_TMP/${NGX_ECHOLINKFILE}" | head -1 | cut -f1 -d"/")
REDISDIR=$(tar -tzf "$DIR_TMP/${NGX_REDISLINKFILE}" | head -1 | cut -f1 -d"/")
if [[ ! -f "${DIR_TMP}/${NGX_MEMCLINKFILE}" || ! -f "${DIR_TMP}/${NGX_SRCACHELINKFILE}"|| ! -f "${DIR_TMP}/${NGX_REDISLINKFILE}" || ! -f "${DIR_TMP}/${NGX_ECHOLINKFILE}" || ! -f "${DIR_TMP}/${NGX_SETMISCLINKFILE}" || ! -f "${DIR_TMP}/${NGX_DEVELKITLINKFILE}" ]] || [[ ! -d "${DIR_TMP}/${MEMCDIR}" || ! -d "${DIR_TMP}/${SRCACHEDIR}"|| ! -d "${DIR_TMP}/${REDISDIR}" || ! -d "${DIR_TMP}/${ECHODIR}" || ! -d "${DIR_TMP}/${SETMISCDIR}" || ! -d "${DIR_TMP}/${DEVELKITDIR}" ]]; then
openrestytarball
fi
# ORESTY_LUANGINX=y|n
if [[ "$ORESTY_LUANGINX" = [yY] ]]; then
NGX_LUAGITLINKDIR=$(tar -tzf "$DIR_TMP/${NGX_LUAGITLINKFILE}" | head -1 | cut -f1 -d"/")
if [[ ! -f "${DIR_TMP}/${NGX_LUANGINXLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUAGITLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUAMEMCACHEDLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUAMYSQLLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUAREDISLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUADNSLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUAUPLOADLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUAWEBSOCKETLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUALOCKLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUASTRINGLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUAREDISPARSERLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUAUPSTREAMCHECKLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUALRUCACHELINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUARESTYCORELINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUAUPSTREAMLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUALOGGERSOCKETLINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUACOOKIELINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUAUPSTREAMCACHELINKFILE}" || ! -f "${DIR_TMP}/${NGX_LUACJSONLINKFILE}" ]] || [[ ! -d "${DIR_TMP}/${NGX_LUANGINXDIR}" || ! -d "${DIR_TMP}/${NGX_LUAGITLINKDIR}" || ! -d "${DIR_TMP}/${NGX_LUAMEMCACHEDDIR}" || ! -d "${DIR_TMP}/${NGX_LUAMYSQLDIR}" || ! -d "${DIR_TMP}/${NGX_LUAREDISDIR}" || ! -d "${DIR_TMP}/${NGX_LUADNSDIR}" || ! -d "${DIR_TMP}/${NGX_LUAUPLOADDIR}" || ! -d "${DIR_TMP}/${NGX_LUAWEBSOCKETDIR}" || ! -d "${DIR_TMP}/${NGX_LUALOCKDIR}" || ! -d "${DIR_TMP}/${NGX_LUASTRINGDIR}" || ! -d "${DIR_TMP}/${NGX_LUAREDISPARSERDIR}" || ! -d "${DIR_TMP}/${NGX_LUAUPSTREAMCHECKDIR}" || ! -d "${DIR_TMP}/${NGX_LUALRUCACHEDIR}" || ! -d "${DIR_TMP}/${NGX_LUARESTYCOREDIR}" || ! -d "${DIR_TMP}/${NGX_LUAUPSTREAMDIR}" || ! -d "${DIR_TMP}/${NGX_LUALOGGERSOCKETDIR}" || ! -d "${DIR_TMP}/${NGX_LUACOOKIEDIR}" || ! -d "${DIR_TMP}/${NGX_LUAUPSTREAMCACHEDIR}" || ! -d "${DIR_TMP}/${NGX_LUACJSONDIR}" ]]; then
openrestytarball
fi
fi
fi
if [[ "$NGINX_PAGESPEEDGITMASTER" = [yY] ]]; then
# if option to download official github based master ngx_pagespeed
# remove old version downloaded & download master tarball instead
cd "$DIR_TMP"
rm -rf release-${NGXPGSPEED_VER}*
nginxpgspeedtarball
fi
}
clear_ps() {
if [ -d /var/ngx_pagespeed_cache ]; then
rm -rf /var/ngx_pagespeed_cache/*
fi
}
function funct_nginxupgrade {
checkmap
# if [ ! -f /usr/local/bin/pcretest ]; then
# wgetver_check
# fi
cecho "**********************************************************************" $boldyellow
cecho "* Nginx Update script - Included in Centmin Extras" $boldgreen
cecho "* Version: $SCRIPT_VERSION - Date: $SCRIPT_DATE - $COPYRIGHT" $boldgreen
cecho "**********************************************************************" $boldyellow
echo " "
cecho "This software comes with no warranty of any kind. You are free to use" $boldyellow
cecho "it for both personal and commercial use as licensed under the GPL." $boldyellow
echo " "
if [ -f /usr/local/lib/libz.so ]; then
echo "Upgrade Note:"
echo "This nginx recompile involves zlib changes which have one time"
echo "service restarts including MariaDB MySQL restart to switch"
echo "from custom zlib shared library back to system zlib library"
echo "for services other than Nginx. Nginx will use custom zlib"
echo "by itself while all other services will revert back to system"
echo "zlib shared library"
fi
echo
if [[ "$UALL" = 'y' ]]; then
nukey=y
else
read -ep "Nginx Upgrade - Would you like to continue? [y/n] " nukey
fi
if [[ "$nukey" = [nN] ]];
then
exit 0
fi
# DIR_TMP="/svr-setup"
if [ ! -d "$DIR_TMP" ]; then
mkdir "$DIR_TMP"
fi
funct_mktempfile
# only run for CentOS 6.x
if [[ "$CENTOS_SEVEN" != '7' ]]; then
if [ ! -f /etc/init.d/nginx ]; then
cp $CUR_DIR/init/nginx /etc/init.d/nginx
chmod +x /etc/init.d/nginx
chkconfig --levels 235 nginx on
fi
fi # CENTOS_SEVEN != 7
if [[ "$UALL" = 'y' ]]; then
ngver=$NGINX_VERSION
recompileopenssl='n'
else
echo ""
read -ep "Install which version of Nginx? (version i.e. type $NGINX_VERSION): " ngver
# if user forgets to type in nginx version and hits
# enter, ngxver will be empty so should fall back to
# the nginx version defined by NGINX_VERSION variable
if [ -z "$ngver" ]; then
LASTEST_NGINXVERS=$(curl -4sL https://nginx.org/en/download.html 2>&1 | egrep -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)
ngver="$LASTEST_NGINXVERS"
fi
# if you set /etc/centminmod/custom_config.inc file to
# NGINX_UPDATEMAINTENANCE=y
# then whenever you run nginx upgrade, you put all sites
# on server into 503 maintenance mode first and once
# updated, disable 503 maintenance mod after
if [[ "$NGINX_UPDATEMAINTENANCE" = [yY] ]]; then
if [ -f /usr/bin/sitestatus ]; then
/usr/bin/sitestatus off
fi
fi
# auto check if static compiled Nginx openssl version matches
# the one defined in centmin.sh OPENSSL_VERSION variable
# if doesn't match then auto recompile the statically set
# OPENSSL_VERSION
AUTOOPENSSLCHECK=$(nginx -V 2>&1 | grep -Eo "$OPENSSL_VERSION")
if [[ "$AUTOOPENSSLCHECK" ]]; then
recompileopenssl='y'
else
recompileopenssl='y'
fi
echo ""
checkgeoip
fi # UALL
## grab newer custom written htpasswd.sh as well
gethtpasswdsh
if [ -f "$(which figlet)" ]; then
figlet -ckf standard "Nginx Auto Backup Conf Directories"
fi
# Backup Nginx CONF
if [ "$NGINXBACKUP" == 'y' ]; then
nginxbackup
fi
# Backup ngx_pagespeed pagespeed.conf
if [[ "$NGINX_PAGESPEED" = [yY] ]]; then
if [[ -f /usr/local/nginx/conf/pagespeed.conf ]]; then
pagespeedbackup
fi
fi
# tasks for updated ngx_pagespeed module parity
pagespeeduptasks
echo "*************************************************"
cecho "* Updating nginx" $boldgreen
echo "*************************************************"
cd "$DIR_TMP"
# nginx Modules / Prerequisites
cecho "Installing nginx Modules / Prerequisites..." $boldgreen
checknginxmodules
nginxzlib_install
if [[ "$GPERFTOOLS_SOURCEINSTALL" = [yY] ]];
then
echo "*************************************************"
cecho "* Source Upgrade Google Perftools" $boldgreen
echo "*************************************************"
if [[ "$(uname -m)" = 'x86_64' ]]; then
# Install libunwind
echo "Compiling libunwind..."
if [ -s "${LIBUNWIND_LINKFILE}" ]; then
cecho "libunwind ${LIBUNWIND_VERSION} Archive found, skipping download..." $boldgreen
else
download_cmd "${LIBUNWIND_LINK}" $WGETRETRY
fi
tar xvzf "${LIBUNWIND_LINKFILE}"
cd "libunwind-${LIBUNWIND_VERSION}"
if [[ "$INITIALINSTALL" != [yY] ]]; then
make clean
fi
./configure
make${MAKETHREADS}
make install
fi
# Install google-perftools
cd "$DIR_TMP"
echo "Compiling google-perftools..."
if [ -s "${GPERFTOOL_LINKFILE}" ]; then
cecho "google-perftools ${GPERFTOOLS_VERSION} Archive found, skipping download..." $boldgreen
else
download_cmd "${GPERFTOOL_LINK}" $WGETRETRY
fi
tar xvzf "${GPERFTOOL_LINKFILE}"
cd "${GPERFTOOL_LINKDIR}"
if [[ "$INITIALINSTALL" != [yY] ]]; then
make clean
fi
if [[ "$(uname -m)" = 'x86_64' ]]; then
./configure --with-tcmalloc-pagesize=$TCMALLOC_PAGESIZE
else
./configure --enable-frame-pointers --with-tcmalloc-pagesize=$TCMALLOC_PAGESIZE
fi
make${MAKETHREADS}
make install
if [ ! -f /etc/ld.so.conf.d/wget.conf ]; then
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
fi
fi # GPERFTOOL_SOURCEINSTALL
# echo ""
# read -ep "Do you want to recompile OpenSSL ? Only needed if you updated OpenSSL version in centmin.sh [y/n]: " recompileopenssl
# echo ""
if [[ "$recompileopenssl" = [yY] || "$LIBRESSL_SWITCH" = [yY] ]]; then
installopenssl
fi # recompileopenssl
if [[ "$PCRE_SOURCEINSTALL" = [yY] ]];
then
echo "*************************************************"
cecho "* Source Install PCRE" $boldgreen
echo "*************************************************"
# Install PCRE
cd "$DIR_TMP"
echo "Compiling PCRE..."
if [ -s "pcre-${PCRE_VERSION}.tar.gz" ]; then
cecho "pcre ${PCRE_VERSION} Archive found, skipping download..." $boldgreen
else
download_cmd "${PCRE_SOURCELINK}" $WGETRETRY
fi
tar "xvzf pcre-${PCRE_VERSION}.tar.gz"
cd "pcre-${PCRE_VERSION}"
if [[ "$INITIALINSTALL" != [yY] ]]; then
make clean
fi
./configure
make${MAKETHREADS}
make install
fi
if [ -f "$(which figlet)" ]; then
figlet -ckf standard "luajit install"
fi
luajitinstall
funct_nginxmodules
check_requestscheme
# Install nginx
cd "$DIR_TMP"
CUR_NGINXVER=$(nginx -v 2>&1 | awk -F '\\/' '{print $2}' |sed -e 's|\.|0|g' | head -n1)
CUR_NGINXUPGRADEVER=$(echo "$ngver" |sed -e 's|\.|0|g' | head -n1)
if [[ "$NGINXPATCH" = [nN] || "$NGINX_HTTP2" = [nN] || "$NGINX_DYNAMICTLS" = [nN] ]]; then
# if centmin.sh option NGINXPATCH=n then disable patches by
# wiping the nginx downloaded source and redownloading a fresh copy
rm -rf nginx-${ngver}*
fi
if [[ "$NGINX_SPDYPATCHED" = [nN] && "$(grep 'ngx_http_spdy_filter' $DIR_TMP/nginx-${ngver}/auto/modules)" ]]; then
# if centmin.sh option NGINX_SPDYPATCHED=n then disable patches by
# wiping the nginx downloaded source and redownloading a fresh copy
rm -rf nginx-${ngver}*
fi
# if [[ "$(nginx -V 2>&1 | grep -Eo 'with-http_v2_module')" = 'with-http_v2_module' ]]; then
# # if existing Nginx server is detected to have HTTP/2 patch compiled, then
# # wipe nginx download source and redownload a fresh copy to ensure you're
# # patching with latest patch http://nginx.org/patches/http2/ available
# rm -rf nginx-${ngver}*
# fi
if [ -f "$(which figlet)" ]; then
figlet -ckf standard "Compile Nginx"
fi
echo "Compiling nginx..."
if [[ "$ngver" = 'master' ]]; then
rm -rf nginx-${ngver}*
git clone --depth=1 https://github.com/nginx/nginx nginx-master
mv nginx-master/auto/configure nginx-master/configure
fi
if [[ -s "nginx-${ngver}.tar.gz" || "$ngver" = 'master' ]]; then
cecho "nginx ${ngver} download found, skipping download..." $boldgreen
else
download_cmd "http://nginx.org/download/nginx-${ngver}.tar.gz" $WGETRETRY
NGINXDOWNLOAD_CHECK=$?
if [[ "$NGINXDOWNLOAD_CHECK" != '0' ]]; then
if [ -f "$(which figlet)" ]; then
figlet -ckf standard "Nginx Failed Download"
fi
echo
echo "!! Nginx Failed Download !!"
echo "try again by running centmin.sh menu option 4"
echo "make sure you type the correct nginx version"
echo "report errors on the forums at community.centminmod.com/forums/8/"
echo
free -m
echo
df -hT
echo
echo "CPU: $(awk -F ': ' '/^model name/ {print $2}' /proc/cpuinfo | head -n1) ($(grep -c "processor" /proc/cpuinfo))"
echo
echo "version increment history"
tail -5 /etc/centminmod-versionlog
if [ -d "${SCRIPT_DIR}/.git" ]; then
echo
echo "last Centmin Mod local git commit entry"
pushd "${SCRIPT_DIR}"
git log --numstat --pretty="%n%h %an %aD %n%s" --shortstat -1
popd
fi
if [[ -d "${SCRIPT_DIR}/.git" ]]; then
echo
echo "last Centmin Mod local git commit entry"
pushd "${SCRIPT_DIR}"
git log --numstat --pretty="%n%h %an %aD %n%s" --shortstat -1
popd
fi
echo
exit
fi
fi
if [[ "$ngver" != 'master' ]]; then
tar xvfz "nginx-${ngver}.tar.gz"
NGINXTAREXTRACT_CHECK=$?
if [[ "$NGINXTAREXTRACT_CHECK" != '0' ]]; then
if [ -f "$(which figlet)" ]; then
figlet -ckf standard "Nginx Tarball Extraction Failed"
fi
echo
echo "!! Nginx Tarball Extraction Failed !!"
echo "try again by running centmin.sh menu option 4"
echo "make sure you type the correct nginx version"
echo "report errors on the forums at community.centminmod.com/forums/8/"
echo
free -m
echo
df -hT
echo
echo "CPU: $(awk -F ': ' '/^model name/ {print $2}' /proc/cpuinfo | head -n1) ($(grep -c "processor" /proc/cpuinfo))"
echo
echo
echo "version increment history"
tail -5 /etc/centminmod-versionlog
if [ -d "${SCRIPT_DIR}/.git" ]; then
echo
echo "last Centmin Mod local git commit entry"
pushd "${SCRIPT_DIR}"
git log --numstat --pretty="%n%h %an %aD %n%s" --shortstat -1
popd
fi
rm -rf "$DIR_TMP/nginx-*.tar.gz"
exit
fi
fi
cd "nginx-${ngver}"
if [[ "$INITIALINSTALL" != [yY] ]]; then
make clean
fi
# set_intelflags
if [[ "$NGINXPATCH" = [yY] ]]; then
echo "*************************************************"
cecho "Nginx Patch Time - $NGINXPATCH_DELAY seconds delay" $boldgreen
cecho "to allow you to patch files" $boldgreen
echo "*************************************************"
patchnginx
fi
if [ -f "$(which figlet)" ]; then
figlet -ckf standard "Nginx Configure"
fi
if [[ "$TIME_NGINX" = [yY] ]]; then
funct_nginxconfigure 2>&1 | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }'
else
funct_nginxconfigure
fi
################
# error check
ERR=$?
if [ $ERR != 0 ]; then
echo -e "\n`date`\nError: $ERR, Nginx configure failed\n"
echo "report errors on the forums at community.centminmod.com/forums/8/"
echo
free -m
echo
df -hT
echo
echo "CPU: $(awk -F ': ' '/^model name/ {print $2}' /proc/cpuinfo | head -n1) ($(grep -c "processor" /proc/cpuinfo))"
echo
echo "version increment history"
tail -5 /etc/centminmod-versionlog
if [ -d "${SCRIPT_DIR}/.git" ]; then
echo
echo "last Centmin Mod local git commit entry"
pushd "${SCRIPT_DIR}"
git log --numstat --pretty="%n%h %an %aD %n%s" --shortstat -1
popd
fi
exit
else
echo -e "\n`date`\nSuccess: Nginx configure ok\n"
fi
# error check
################
if [ -f "$(which figlet)" ]; then
figlet -ckf standard "Nginx Make"
fi
# detect OpenSSL 1.1.0 for make -jXX support
DETECTOPENSSL_ONEZERO=$(echo $OPENSSL_VERSION | cut -d . -f1-2)
DETECTOPENSSL_ONEONE=$(echo $OPENSSL_VERSION | cut -d . -f1-3 | grep -o 1.1.1)
if [[ "$LIBRESSL_SWITCH" = [yY] ]]; then
time make${MAKETHREADS}
else
if [[ "$DETECTOPENSSL_ONEZERO" = '1.1' ]] || [[ "$DETECTOPENSSL_ONEONE" = '1.1.1' ]]; then
time make${MAKETHREADS}
else
time make
fi
fi
ERR=$?
sar_call
if [[ "$STRIPNGINX" = [yY] ]]; then
if [ -f objs/nginx ]; then
echo
echo "strip nginx binary..."
ls -lah objs/nginx
strip -s objs/nginx
ls -lah objs/nginx
echo
fi
fi
################
# error check
if [ $ERR != 0 ]; then
echo -e "\n`date`\nError: $ERR, Nginx make failed\n"
echo "report errors on the forums at community.centminmod.com/forums/8/"
echo
free -m
echo
df -hT
echo
echo "CPU: $(awk -F ': ' '/^model name/ {print $2}' /proc/cpuinfo | head -n1) ($(grep -c "processor" /proc/cpuinfo))"
echo
echo "version increment history"
tail -5 /etc/centminmod-versionlog
if [ -d "${SCRIPT_DIR}/.git" ]; then
echo
echo "last Centmin Mod local git commit entry"
pushd "${SCRIPT_DIR}"
git log --numstat --pretty="%n%h %an %aD %n%s" --shortstat -1
popd
fi
exit
else
echo -e "\n`date`\nSuccess: Nginx make ok\n"
fi
# error check
################
if [[ "$CENTOS_SEVEN" = '7' ]]; then
systemctl daemon-reload
fi
GETNGXPID=$(cat /usr/local/nginx/logs/nginx.pid)
GETNGXPPID=$(ps awx -o pid,ppid,command | grep 'nginx: master' | egrep -v '(nginx_upgrade|amplify|php-fpm|hhvm)' | egrep -v grep | awk '{print $1}')
if [[ "$NGINX_ZERODT" = [nN] ]]; then
# cmservice nginx stop
/usr/local/sbin/nginx -s stop >/dev/null 2>&1
# speed up nginx wait time if not many vhosts are on server
if [[ "$(ls /usr/local/nginx/conf/conf.d/ | wc -l)" -le 5 ]]; then
NGINXUPGRADESLEEP=4
fi
# sleep "$NGINXUPGRADESLEEP"
sleep 3
NGINXPSCHECK=$(ps --no-heading -C nginx)
if [ ! -z "$NGINXPSCHECK" ]; then
echo ""
echo "nginx seems to be still running, trying to stop it again..."
echo ""
# /etc/init.d/nginx stop and suppress any error messages
/usr/local/sbin/nginx -s stop >/dev/null 2>&1
sleep "$NGINXUPGRADESLEEP"
fi
elif [[ "$NGINX_ZERODT" = [yY] ]]; then
echo "---------------------------------------------------------------------------"
echo "nginx master id: $GETNGXPID"
echo
echo "---------------------------------------------------------------------------"
curl -s -4 localhost/nginx_status
echo "---------------------------------------------------------------------------"
ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx: |PID)' | egrep -v '(nginx_upgrade|amplify|php-fpm|hhvm)' | egrep -v grep
echo "---------------------------------------------------------------------------"
fi
if [ -f "$(which figlet)" ]; then
figlet -ckf standard "Nginx Make Install"
fi
time make install
ERR=$?
sar_call
if [[ "$CLANG" = [yY] ]]; then
unset CC
unset CXX
#unset CCACHE_CPP2
export CC="ccache /usr/bin/gcc"
export CXX="ccache /usr/bin/g++"
fi
# unset_intelflags
################
# error check
if [ $ERR = 0 ]; then
detect_tlsonethree
fi
if [ $ERR != 0 ]; then
echo -e "\n`date`\nError: $ERR, Nginx wasn't installed properly\n"
echo "report errors on the forums at community.centminmod.com/forums/8/"
echo
free -m
echo
df -hT
echo
echo "CPU: $(awk -F ': ' '/^model name/ {print $2}' /proc/cpuinfo | head -n1) ($(grep -c "processor" /proc/cpuinfo))"
echo
echo "version increment history"
tail -5 /etc/centminmod-versionlog
if [ -d "${SCRIPT_DIR}/.git" ]; then
echo
echo "last Centmin Mod local git commit entry"
pushd "${SCRIPT_DIR}"
git log --numstat --pretty="%n%h %an %aD %n%s" --shortstat -1
popd
fi
if [ -f objs/autoconf.err ]; then
cat objs/autoconf.err > "${CENTMINLOGDIR}/nginx_autoconf.err.${DT}.log"
fi
exit
else
if [ -f objs/autoconf.err ]; then
cat objs/autoconf.err > "${CENTMINLOGDIR}/nginx_autoconf.err.${DT}.log"
fi
echo -e "\n`date`\nSuccess: Nginx was installed properly\n"
if [[ "$NGINX_HTTP2" = [yY] && "$NGINX_SPDYPATCHED" = [yY] ]] && [[ "$NGX_VEREVAL" -ge '10907' ]]; then
# only apply auto vhost changes forNginx HTTP/2
# if Nginx version is >= 1.9.3 and <1.9.5 OR >= 1.9.5
if [[ "$NGX_VEREVAL" -ge '10907' ]]; then
for v in "$(ls /usr/local/nginx/conf/conf.d/*.conf)"; do echo "$v"; egrep -n 'ssl spdy|spdy_headers_comp|Alternate-Protocol' $v; echo "---"; sed -i 's|ssl http2|ssl spdy http2|g' $v; sed -i 's|# spdy_headers_comp| spdy_headers_comp|g' $v; sed -i 's|# add_header Alternate-Protocol| add_header Alternate-Protocol|g' $v; egrep -n 'ssl http2|spdy_headers_comp|Alternate-Protocol' $v;done
fi
if [ -f /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf ]; then
sed -i 's|ssl http2|ssl spdy http2|g' /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf
sed -i 's|#spdy_headers_comp|spdy_headers_comp|g' /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf
sed -i 's|#add_header Alternate-Protocol|add_header Alternate-Protocol|g' /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf
fi
elif [[ "$NGINX_HTTP2" = [yY] ]] && [[ "$NGX_VEREVAL" -ge '10903' ]]; then
# only apply auto vhost changes forNginx HTTP/2
# if Nginx version is >= 1.9.3 and <1.9.5 OR >= 1.9.5
if [[ "$NGX_VEREVAL" -ge '10903' && "$NGX_VEREVAL" -lt '10905' ]] || [[ "$NGX_VEREVAL" -ge '10905' ]]; then
for v in "$(ls /usr/local/nginx/conf/conf.d/*.conf)"; do
echo "$v";
egrep -n 'ssl spdy|spdy_headers_comp|Alternate-Protocol' $v;
echo "---";
if [[ "$(grep 'ssl spdy http2' $v)" ]]; then
sed -i 's|ssl spdy http2|ssl http2|g' $v;
sed -i 's| spdy_headers_comp| #spdy_headers_comp|g' $v;
sed -i 's| add_header Alternate-Protocol| #add_header Alternate-Protocol|g' $v;
else
sed -i 's|ssl spdy|ssl http2|g' $v;
sed -i 's| spdy_headers_comp| #spdy_headers_comp|g' $v;
sed -i 's| add_header Alternate-Protocol| #add_header Alternate-Protocol|g' $v;
fi
egrep -n 'ssl http2|spdy_headers_comp|Alternate-Protocol' $v;
done
fi
if [ -f /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf ]; then
sed -i 's|ssl spdy|ssl http2|g' /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf
sed -i 's|spdy_headers_comp|#spdy_headers_comp|g' /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf
sed -i 's|add_header Alternate-Protocol|#add_header Alternate-Protocol|g' /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf
fi
elif [[ "$NGINX_HTTP2" = [nN] || "$NGINX_SPDY" = [yY] ]]; then
for v in "$(ls /usr/local/nginx/conf/conf.d/*.conf)"; do echo "$v"; egrep -n 'ssl http2|#spdy_headers_comp|#Alternate-Protocol' $v; egrep -n 'ssl spdy|spdy_headers_comp' $v; echo "---"; sed -i 's|ssl http2|ssl spdy|g' $v; sed -i 's| #spdy_headers_comp| spdy_headers_comp|g' $v; sed -i 's| #add_header Alternate-Protocol| add_header Alternate-Protocol|g' $v; egrep -n 'ssl spdy|spdy_headers_comp|Alternate-Protocol' $v;done
if [ -f /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf ]; then
sed -i 's|ssl http2|ssl spdy|g' /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf
sed -i 's|#spdy_headers_comp|spdy_headers_comp|g' /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf
sed -i 's|#add_header Alternate-Protocol|add_header Alternate-Protocol|g' /usr/local/nginx/conf/conf.d/phpmyadmin_ssl.conf
fi
fi
if [[ "$CENTOS_SEVEN" = '7' ]]; then
systemctl daemon-reload
fi
# empty pagespeed cache
clear_ps
# zlibsymlink_fix
if [[ "$NGINX_ZERODT" = [nN] ]]; then
/etc/init.d/nginx restart
elif [[ "$NGINX_ZERODT" = [yY] ]]; then
echo "---------------------------------------------------------------------------"
echo "nginx master id: $GETNGXPID"
echo "---------------------------------------------------------------------------"
curl -s -4 localhost/nginx_status
echo "---------------------------------------------------------------------------"
echo "kill -USR2 $GETNGXPID"
kill -USR2 $GETNGXPID
sleep 3
ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx: |PID)' | egrep -v '(nginx_upgrade|amplify|php-fpm|hhvm)' | egrep -v grep
echo
ls -lah /usr/local/sbin/nginx*
echo "---------------------------------------------------------------------------"
curl -s -4 localhost/nginx_status
echo "---------------------------------------------------------------------------"
echo "kill -WINCH $GETNGXPID"
kill -WINCH $GETNGXPID
sleep 3
ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx: |PID)' | egrep -v '(nginx_upgrade|amplify|php-fpm|hhvm)' | egrep -v grep
echo "---------------------------------------------------------------------------"
curl -s -4 localhost/nginx_status
echo "---------------------------------------------------------------------------"
echo " waiting for old nginx worker processes to exit..."
while [[ "$(ps awx -o ppid,command | grep 'nginx: worker' | egrep -v '(nginx_upgrade|amplify|php-fpm|hhvm)' | egrep -v grep | awk '{print $1}' | uniq)" = "$GETNGXPPID" ]]; do
echo " checking... worker child PPID=$GETNGXPPID exists"
sleep 3
done
echo "---------------------------------------------------------------------------"
echo "kill -QUIT $GETNGXPID"
kill -QUIT $GETNGXPID
sleep 3
ps axw -o pid,ppid,user,%cpu,vsz,wchan,command | egrep '(nginx: |PID)' | egrep -v '(nginx_upgrade|amplify|php-fpm|hhvm)' | egrep -v grep
echo "---------------------------------------------------------------------------"
curl -s -4 localhost/nginx_status
echo "---------------------------------------------------------------------------"
fi
# cecho "Checking OpenSSL version used by Nginx..." $boldyellow
# SSLIB=$(ldd `which nginx` | grep ssl | awk '{print $3}')
# OPENSSLVER_CHECK=$(strings $SSLIB | grep "^OpenSSL ")
# echo $OPENSSLVER_CHECK
CBODYCHECK=$(grep 'client_body_in_file_only on' /usr/local/nginx/conf/nginx.conf)
if [ $CBODYCHECK ]; then
sed -i 's/client_body_in_file_only on/client_body_in_file_only off/g' /usr/local/nginx/conf/nginx.conf
fi
geoinccheck
geoipphp
mimefix
if [ -f "$(which figlet)" ]; then
figlet -ckf standard "Nginx Cleanup"
fi
# as nginx-sticky-module-ng nginx module https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng
# now uses master branch, if enabled via NGINX_STICKY=y always remove existing master tarball and
# redownload again to get latest
if [[ "$NGINX_STICKY" = [yY] ]]; then
if [[ -f "$DIR_TMP/${NGX_STICKYLINKFILE}" && "$(echo "$DIR_TMP/${NGX_STICKYLINKFILE}")" != '/svr-setup/' ]]; then
rm -rf "$DIR_TMP/${NGX_STICKYLINKFILE}"
fi
if [[ -d "${DIR_TMP}/${NGX_STICKYDIR}" && "$(echo "${DIR_TMP}/${NGX_STICKYDIR}")" != '/svr-setup/' ]]; then
rm -rf "${DIR_TMP}/${NGX_STICKYDIR}"
fi
fi
# clean up /svr-setup downloads directory of older PHP source tarball/directories
find "$DIR_TMP" -maxdepth 1 \( -name 'nginx-1*' ! -name "nginx-${ngver}*" \) -print