forked from sanvu88/ubuntu-lemp-stack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker
2717 lines (2406 loc) · 95.2 KB
/
docker
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
#!/bin/bash
######################################################################
# Auto Install & Optimize LEMP Stack on Ubuntu #
# #
# Author: Sanvv - HOSTVN Technical #
# Website: https://hostvn.vn #
# #
# Please do not remove copyright. Thank! #
# Please do not copy under any circumstance for commercial reason! #
######################################################################
check_dns=$(grep -rnw "/etc/resolv.conf" -e "1.1.1.1")
if [[ -z $check_dns ]]; then
echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf > /dev/null
fi
# shellcheck disable=SC2207
DIR=$(pwd)
# Set Color
RED='\033[0;31m'
NC='\033[0m'
SCRIPTS_VERSION="0.1.0"
IPADDRESS=$(curl -s http://cyberpanel.sh/?ip)
DIR=$(pwd)
BASH_DIR="/var/hostvn"
GITHUB_RAW_LINK="https://raw.githubusercontent.com"
EXT_LINK="https://scripts.hostvn.net"
UPDATE_LINK="https://scripts.hostvn.net/update"
FILE_INFO="${BASH_DIR}/.hostvn.conf"
HOSTNAME=$(hostname)
PHP2_RELEASE="no"
# Service Version
PHPMYADMIN_VERSION=$(curl -s ${UPDATE_LINK}/version | grep "phpmyadmin_version=" | cut -f2 -d'=')
MARIADB_VERSION=$(curl -s ${UPDATE_LINK}/version | grep "mariadb_version=" | cut -f2 -d'=')
# shellcheck disable=SC2207
PHP_VERSION='7.4'
PHP1_CONFIG_PATH="/etc/php/${PHP_VERSION}/fpm"
PHP1_INI_PATH="${PHP1_CONFIG_PATH}/conf.d"
PHP1_POOL_PATH="${PHP1_CONFIG_PATH}/pool.d"
PHP1_CLI_PATH="/etc/php/${PHP_VERSION}/cli/conf.d"
# Random Port
RANDOM_ADMIN_PORT='53302'
# Dir
DEFAULT_DIR_WEB="/usr/share/nginx/html"
DEFAULT_DIR_TOOL="/usr/share/nginx/private"
USR_DIR="/usr/share"
# Get info VPS
CPU_CORES=$(grep -c "processor" /proc/cpuinfo)
RAM_TOTAL=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
SWAP_TOTAL=$(awk '/SwapFree/ {print $2}' /proc/meminfo)
PHP_MEM=${RAM_TOTAL}+${SWAP_TOTAL}
MAX_CLIENT=$((CPU_CORES * 1024))
rm -rf "${DIR}"/hostvn
############################################
# Function
############################################
cd_dir() {
cd "$1" || return
}
gen_pass() {
PASS_LEN=$(perl -le 'print int(rand(6))+9')
START_LEN=$(perl -le 'print int(rand(8))+1')
END_LEN=$((PASS_LEN - START_LEN))
NUMERIC_CHAR=$(perl -le 'print int(rand(10))')
PASS_START=$(perl -le "print map+(A..Z,a..z,0..9)[rand 62],0..$START_LEN")
PASS_END=$(perl -le "print map+(A..Z,a..z,0..9)[rand 62],0..$END_LEN")
PASS=${PASS_START}${NUMERIC_CHAR}${PASS_END}
echo "$PASS"
}
random_string() {
STRING=$(perl -le "print map+(A..Z,a..z,0..9)[rand 62],0..$1")
echo "$STRING"
}
############################################
# Prepare install
############################################
create_bash_dir() {
mkdir -p /home/backup
chmod 710 /home/backup
chmod 711 /home
mkdir -p "${BASH_DIR}"
mkdir -p "${BASH_DIR}"/custom
}
# Admin Email
set_email() {
clear
while true; do
read -r -p "Nhap vao email cua ban: " ADMIN_EMAIL
echo
if [[ "${ADMIN_EMAIL}" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$ ]]; then
echo "Email cua ban la: ${ADMIN_EMAIL}."
break
else
echo "Email ban nhap khong chinh xac vui long nhap lai."
fi
done
}
###########################################
# Install LEMP Stack
############################################
install_nginx(){
apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip uuid-dev -y
apt autoremove -y
UPDATE_LINK="https://scripts.hostvn.net/update"
MODULE_PATH="/usr/share/nginx_module"
mkdir -p "${MODULE_PATH}"
NGINX_VERSION=$(curl -s ${UPDATE_LINK}/version | grep "nginx_version=" | cut -f2 -d'=')
NPS_VERSION=$(curl -s ${UPDATE_LINK}/version | grep "nps_version=" | cut -f2 -d'=')
ngx_cache_purge_version=$(curl -s ${UPDATE_LINK}/version | grep "ngx_cache_purge_version=" | cut -f2 -d'=')
more_clear_headers_v=$(curl -s ${UPDATE_LINK}/version | grep "more_clear_headers_v=" | cut -f2 -d'=')
openssl_version=$(curl -s ${UPDATE_LINK}/version | grep "openssl_version=" | cut -f2 -d'=')
pcre_version=$(curl -s ${UPDATE_LINK}/version | grep "pcre_version=" | cut -f2 -d'=')
zlib_version=$(curl -s ${UPDATE_LINK}/version | grep "zlib_version=" | cut -f2 -d'=')
cd_dir "${MODULE_PATH}"
wget -O- https://github.com/apache/incubator-pagespeed-ngx/archive/v"${NPS_VERSION}".tar.gz | tar -xz
nps_dir=$(find . -name "*pagespeed-ngx-${NPS_VERSION}" -type d)
cd_dir "$nps_dir"
NPS_RELEASE_NUMBER=${NPS_VERSION/beta/}
NPS_RELEASE_NUMBER=${NPS_VERSION/stable/}
psol_url=https://dl.google.com/dl/page-speed/psol/${NPS_RELEASE_NUMBER}.tar.gz
[ -e scripts/format_binary_url.sh ] && psol_url=$(scripts/format_binary_url.sh PSOL_BINARY_URL)
wget -O- "${psol_url}" | tar -xz
cd_dir "${MODULE_PATH}"
wget -O- http://nginx.org/download/nginx-"${NGINX_VERSION}".tar.gz | tar -xz
wget -O- http://scripts.hostvn.net/ubuntu/modules/ngx_cache_purge-"${ngx_cache_purge_version}".tar.gz | tar -xz
wget -O- http://scripts.hostvn.net/ubuntu/modules/openssl-OpenSSL_"${openssl_version}".tar.gz | tar -xz
wget -O- ftp://ftp.pcre.org/pub/pcre/pcre-"${pcre_version}".tar.gz | tar -xz
wget -O- https://www.zlib.net/zlib-"${zlib_version}".tar.gz | tar -xz
wget -O- http://scripts.hostvn.net/ubuntu/modules/headers-more-nginx-module-"${more_clear_headers_v}".tar.gz | tar -xz
git clone --depth 1 https://github.com/google/ngx_brotli
cd_dir ngx_brotli && git submodule update --init
cd_dir "${MODULE_PATH}"/nginx-"${NGINX_VERSION}"/
./configure \
"--user=nginx" \
"--group=nginx" \
"--prefix=/usr" \
"--sbin-path=/usr/sbin" \
"--conf-path=/etc/nginx/nginx.conf" \
"--pid-path=/var/run/nginx.pid" \
"--http-log-path=/var/log/nginx/access_log" \
"--error-log-path=/var/log/nginx/error_log" \
"--without-mail_imap_module" \
"--without-mail_smtp_module" \
"--with-http_ssl_module" \
"--with-http_realip_module" \
"--with-http_stub_status_module" \
"--with-http_gzip_static_module" \
"--with-http_dav_module" \
"--with-http_v2_module" \
"--with-pcre=../pcre-${pcre_version}" \
"--with-pcre-jit" \
"--with-zlib=../zlib-${zlib_version}" \
"--with-openssl=../openssl-OpenSSL_${openssl_version}" \
"--with-openssl-opt=no-nextprotoneg" \
"--add-module=../ngx_cache_purge-${ngx_cache_purge_version}" \
"--add-module=../incubator-pagespeed-ngx-${NPS_VERSION}" \
"--add-module=../headers-more-nginx-module-${more_clear_headers_v}" \
"--add-module=../ngx_brotli" \
"--with-cc-opt='-D FD_SETSIZE=32768'"
make && make install
if [[ -d "/usr/lib/nginx/modules" && ! -d "/etc/nginx/modules" ]]; then
ln -s /usr/lib/nginx/modules /etc/nginx/modules
fi
adduser --system --home /nonexistent --shell /bin/false --no-create-home --disabled-login --disabled-password \
--gecos "nginx user" --group nginx
rm -rf /etc/systemd/system/nginx.service
cat >> "/etc/systemd/system/nginx.service" << EOnginx_service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP \$MAINPID
ExecStop=/bin/kill -s QUIT \$MAINPID
PrivateTmp=true
LimitMEMLOCK=infinity
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOnginx_service
sudo systemctl enable nginx.service
sudo systemctl start nginx.service
cd_dir "${DIR}"
}
install_mariadb() {
apt-get install software-properties-common apt-transport-https -y
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc' << EOF
EOF
OS_VER=$(grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"')
if [ "${OS_VER}" == "18.04" ]; then
sudo add-apt-repository "deb [arch=amd64,arm64,ppc64el] http://sgp1.mirrors.digitalocean.com/mariadb/repo/${MARIADB_VERSION}/ubuntu bionic main"
elif [ "${OS_VER}" == "20.04" ]; then
sudo add-apt-repository "deb [arch=amd64,arm64,ppc64el] http://sgp1.mirrors.digitalocean.com/mariadb/repo/${MARIADB_VERSION}/ubuntu focal main"
else
clear
printf "%s" "${RED}VPS cua ban khong the ket noi toi server cua MaraiDB. Vui long kiem tra lai Network cua VPS${NC}"
printf "%s" "${RED}Huy cai dat.${NC}"
exit
fi
sudo apt update
sudo apt install mariadb-server
}
install_php() {
add-apt-repository ppa:ondrej/php <<EOF
EOF
apt-get update -y
apt-get -y install php"${PHP_VERSION}" php"${PHP_VERSION}"-fpm php"${PHP_VERSION}"-ldap php"${PHP_VERSION}"-zip \
php"${PHP_VERSION}"-cli php"${PHP_VERSION}"-mysql php"${PHP_VERSION}"-gd php"${PHP_VERSION}"-xml \
php"${PHP_VERSION}"-mbstring php"${PHP_VERSION}"-common php"${PHP_VERSION}"-soap \
php"${PHP_VERSION}"-curl php"${PHP_VERSION}"-bcmath php"${PHP_VERSION}"-snmp php"${PHP_VERSION}"-pspell \
php"${PHP_VERSION}"-gmp php"${PHP_VERSION}"-intl php"${PHP_VERSION}"-imap php"${PHP_VERSION}"-enchant \
php"${PHP_VERSION}"-xmlrpc php"${PHP_VERSION}"-tidy php"${PHP_VERSION}"-opcache php"${PHP_VERSION}"-cli \
php"${PHP_VERSION}"-dev php"${PHP_VERSION}"-imagick php"${PHP_VERSION}"-sqlite3 php"${PHP_VERSION}"-json
if [ -f "/usr/lib/systemd/system/php${PHP_VERSION}-fpm.service" ]; then
sed -i '/ExecReload=/a LimitNOFILE=65535' /usr/lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/ExecReload=/a LimitMEMLOCK=infinity' /usr/lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/LimitNOFILE=65535/a PrivateTmp=true' /usr/lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/PrivateTmp=true/a ProtectKernelModules=true' /usr/lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/ProtectKernelModules=true/a ProtectKernelTunables=true' /usr/lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/ProtectKernelTunables=true/a ProtectControlGroups=true' /usr/lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/ProtectControlGroups=true/a RestrictRealtime=true' /usr/lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/RestrictRealtime=true/a RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX' /usr/lib/systemd/system/php"${PHP_VERSION}"-fpm.service
systemctl daemon-reload
fi
if [ -f "/lib/systemd/system/php${PHP_VERSION}-fpm.service" ]; then
sed -i '/ExecReload=/a LimitNOFILE=65535' /lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/ExecReload=/a LimitMEMLOCK=infinity' /lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/LimitNOFILE=65535/a PrivateTmp=true' /lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/PrivateTmp=true/a ProtectKernelModules=true' /lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/ProtectKernelModules=true/a ProtectKernelTunables=true' /lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/ProtectKernelTunables=true/a ProtectControlGroups=true' /lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/ProtectControlGroups=true/a RestrictRealtime=true' /lib/systemd/system/php"${PHP_VERSION}"-fpm.service
sed -i '/RestrictRealtime=true/a RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX' /lib/systemd/system/php"${PHP_VERSION}"-fpm.service
systemctl daemon-reload
fi
}
install_phpmyadmin() {
DECLARE="declare(strict_types=1);"
mkdir -p "${DEFAULT_DIR_TOOL}"
cd_dir "${DEFAULT_DIR_TOOL}"
wget https://files.phpmyadmin.net/phpMyAdmin/"${PHPMYADMIN_VERSION}"/phpMyAdmin-"${PHPMYADMIN_VERSION}"-english.zip
unzip phpMyAdmin-"${PHPMYADMIN_VERSION}"-english.zip
mv phpMyAdmin-"${PHPMYADMIN_VERSION}"-english phpmyadmin
rm -rf phpMyAdmin-"${PHPMYADMIN_VERSION}"-english.zip
rm -rf "${DEFAULT_DIR_TOOL}"/phpmyadmin/setup
mv "${DEFAULT_DIR_TOOL}"/phpmyadmin/config.sample.inc.php "${DEFAULT_DIR_TOOL}"/phpmyadmin/config.inc.php
BLOWFISH_SECRET=$(random_string 64)
mkdir -p "${DEFAULT_DIR_TOOL}"/phpmyadmin/tmp
cat >"${DEFAULT_DIR_TOOL}/phpmyadmin/config.inc.php" <<EOCONFIGINC
<?php
${DECLARE}
\$cfg['blowfish_secret'] = '${BLOWFISH_SECRET}';
\$i = 0;
\$i++;
\$cfg['Servers'][\$i]['auth_type'] = 'cookie';
\$cfg['Servers'][\$i]['host'] = 'localhost';
\$cfg['Servers'][\$i]['connect_type'] = 'tcp';
\$cfg['Servers'][\$i]['compress'] = false;
\$cfg['Servers'][\$i]['AllowNoPassword'] = false;
\$cfg['UploadDir'] = '';
\$cfg['SaveDir'] = '';
\$cfg['PmaNoRelation_DisableWarning'] = true;
\$cfg['VersionCheck'] = false;
\$cfg['TempDir'] = '${DEFAULT_DIR_TOOL}/phpmyadmin/tmp';
\$cfg['CaptchaLoginPublicKey'] = '';
\$cfg['CaptchaLoginPrivateKey'] = '';
\$cfg['ExecTimeLimit'] = 600;
\$cfg['DefaultCharset'] = 'utf8';
\$cfg['DefaultConnectionCollation'] = 'utf8_general_ci';
EOCONFIGINC
chown -R nginx:nginx "${DEFAULT_DIR_TOOL}"/phpmyadmin
chown -R nginx:nginx "${DEFAULT_DIR_TOOL}"/phpmyadmin
cat >> "/opt/phpmyadmin.temp" <<EOphpmyadmin_temp
CREATE DATABASE IF NOT EXISTS phpmyadmin;
FLUSH PRIVILEGES;
EOphpmyadmin_temp
mysql -u root -p"${sql_root_pass}" < /opt/phpmyadmin.temp
rm -f /opt/phpmyadmin.temp
curl -o phpmyadmin.sql "${EXT_LINK}"/phpmyadmin.sql
mysql -u root -p"${sql_root_pass}" phpmyadmin < phpmyadmin.sql
rm -rf phpmyadmin.sql
}
############################################
# Install Composer
############################################
install_composer() {
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# Composer 1
wget https://getcomposer.org/download/1.10.20/composer.phar
mv composer.phar /usr/local/bin/composer1
chmod +x /usr/local/bin/composer1
}
############################################
# Install WP-CLI
############################################
install_wp_cli() {
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
mv wp-cli.phar /usr/local/bin/wp
}
############################################
# Dynamic calculation
############################################
php_memory_calculation() {
if [[ "${PHP_MEM}" -le '262144' ]]; then
OPCACHE_MEM='128'
MAX_MEMORY='128'
PHP_REAL_PATH_LIMIT='512k'
PHP_REAL_PATH_TTL='14400'
MAX_INPUT_VARS="6000"
elif [[ "${PHP_MEM}" -gt '262144' && "${PHP_MEM}" -le '393216' ]]; then
OPCACHE_MEM='128'
MAX_MEMORY='128'
PHP_REAL_PATH_LIMIT='640k'
PHP_REAL_PATH_TTL='21600'
MAX_INPUT_VARS="6000"
elif [[ "${PHP_MEM}" -gt '393216' && "${PHP_MEM}" -le '524288' ]]; then
OPCACHE_MEM='128'
MAX_MEMORY='128'
PHP_REAL_PATH_LIMIT='768k'
PHP_REAL_PATH_TTL='21600'
MAX_INPUT_VARS="6000"
elif [[ "${PHP_MEM}" -gt '524288' && "${PHP_MEM}" -le '1049576' ]]; then
OPCACHE_MEM='144'
MAX_MEMORY='160'
PHP_REAL_PATH_LIMIT='768k'
PHP_REAL_PATH_TTL='28800'
MAX_INPUT_VARS="6000"
elif [[ "${PHP_MEM}" -gt '1049576' && "${PHP_MEM}" -le '2097152' ]]; then
OPCACHE_MEM='160'
MAX_MEMORY='320'
PHP_REAL_PATH_LIMIT='1536k'
PHP_REAL_PATH_TTL='28800'
MAX_INPUT_VARS="6000"
elif [[ "${PHP_MEM}" -gt '2097152' && "${PHP_MEM}" -le '3145728' ]]; then
OPCACHE_MEM='192'
MAX_MEMORY='384'
PHP_REAL_PATH_LIMIT='2048k'
PHP_REAL_PATH_TTL='43200'
MAX_INPUT_VARS="6000"
elif [[ "${PHP_MEM}" -gt '3145728' && "${PHP_MEM}" -le '4194304' ]]; then
OPCACHE_MEM='224'
MAX_MEMORY='512'
PHP_REAL_PATH_LIMIT='3072k'
PHP_REAL_PATH_TTL='43200'
MAX_INPUT_VARS="6000"
elif [[ "${PHP_MEM}" -gt '4194304' && "${PHP_MEM}" -le '8180000' ]]; then
OPCACHE_MEM='288'
MAX_MEMORY='640'
PHP_REAL_PATH_LIMIT='4096k'
PHP_REAL_PATH_TTL='43200'
MAX_INPUT_VARS="10000"
elif [[ "${PHP_MEM}" -gt '8180000' && "${PHP_MEM}" -le '16360000' ]]; then
OPCACHE_MEM='320'
MAX_MEMORY='800'
PHP_REAL_PATH_LIMIT='4096k'
PHP_REAL_PATH_TTL='43200'
MAX_INPUT_VARS="10000"
elif [[ "${PHP_MEM}" -gt '16360000' && "${PHP_MEM}" -le '32400000' ]]; then
OPCACHE_MEM='480'
MAX_MEMORY='1024'
PHP_REAL_PATH_LIMIT='4096k'
PHP_REAL_PATH_TTL='43200'
MAX_INPUT_VARS="10000"
elif [[ "${PHP_MEM}" -gt '32400000' && "${PHP_MEM}" -le '64800000' ]]; then
OPCACHE_MEM='600'
MAX_MEMORY='1280'
PHP_REAL_PATH_LIMIT='4096k'
PHP_REAL_PATH_TTL='43200'
MAX_INPUT_VARS="10000"
elif [[ "${PHP_MEM}" -gt '64800000' ]]; then
OPCACHE_MEM='800'
MAX_MEMORY='2048'
PHP_REAL_PATH_LIMIT='8192k'
PHP_REAL_PATH_TTL='86400'
MAX_INPUT_VARS="10000"
fi
}
cal_ssl_cache_size() {
if [[ ${RAM_TOTAL} -gt 500000 && ${RAM_TOTAL} -le 800000 ]]; then
SSL_CACHE_SIZE=20
elif [[ ${RAM_TOTAL} -gt 800000 && ${RAM_TOTAL} -le 1000000 ]]; then
SSL_CACHE_SIZE=40
elif [[ ${RAM_TOTAL} -gt 1000000 && ${RAM_TOTAL} -le 1880000 ]]; then
SSL_CACHE_SIZE=60
elif [[ ${RAM_TOTAL} -gt 1880000 && ${RAM_TOTAL} -le 2890000 ]]; then
SSL_CACHE_SIZE=80
elif [[ ${RAM_TOTAL} -gt 2890000 && ${RAM_TOTAL} -le 3890000 ]]; then
SSL_CACHE_SIZE=150
elif [[ ${RAM_TOTAL} -gt 3890000 && ${RAM_TOTAL} -le 7800000 ]]; then
SSL_CACHE_SIZE=300
elif [[ ${RAM_TOTAL} -gt 7800000 && ${RAM_TOTAL} -le 15600000 ]]; then
SSL_CACHE_SIZE=500
elif [[ ${RAM_TOTAL} -gt 15600000 && ${RAM_TOTAL} -le 23600000 ]]; then
SSL_CACHE_SIZE=1000
elif [[ ${RAM_TOTAL} -gt 23600000 ]]; then
SSL_CACHE_SIZE=2000
else
SSL_CACHE_SIZE=10
fi
}
php_parameter() {
if [[ ${CPU_CORES} -ge 4 && ${CPU_CORES} -lt 6 && ${RAM_TOTAL} -gt 1049576 && ${RAM_TOTAL} -le 2097152 ]]; then
PM_MAX_CHILDREN=$((CPU_CORES * 6))
PM_MAX_REQUEST=2000
elif [[ ${CPU_CORES} -ge 4 && ${CPU_CORES} -lt 6 && ${RAM_TOTAL} -gt 2097152 && ${RAM_TOTAL} -le 3145728 ]]; then
PM_MAX_CHILDREN=$((CPU_CORES * 6))
PM_MAX_REQUEST=2000
elif [[ ${CPU_CORES} -ge 4 && ${CPU_CORES} -lt 6 && ${RAM_TOTAL} -gt 3145728 && ${RAM_TOTAL} -le 4194304 ]]; then
PM_MAX_CHILDREN=$((CPU_CORES * 6))
PM_MAX_REQUEST=2000
elif [[ ${CPU_CORES} -ge 4 && ${CPU_CORES} -lt 6 && ${RAM_TOTAL} -gt 4194304 ]]; then
PM_MAX_CHILDREN=$((CPU_CORES * 6))
PM_MAX_REQUEST=2000
elif [[ ${CPU_CORES} -ge 6 && ${CPU_CORES} -lt 8 && ${RAM_TOTAL} -gt 3145728 && ${RAM_TOTAL} -le 4194304 ]]; then
PM_MAX_CHILDREN=$((CPU_CORES * 6))
PM_MAX_REQUEST=2000
elif [[ ${CPU_CORES} -ge 6 && ${CPU_CORES} -lt 8 && ${RAM_TOTAL} -gt 4194304 ]]; then
PM_MAX_CHILDREN=$((CPU_CORES * 6))
PM_MAX_REQUEST=2000
elif [[ ${CPU_CORES} -ge 8 && ${CPU_CORES} -lt 16 && ${RAM_TOTAL} -gt 3145728 && ${RAM_TOTAL} -le 4194304 ]]; then
PM_MAX_CHILDREN=$((CPU_CORES * 6))
PM_MAX_REQUEST=2000
elif [[ ${CPU_CORES} -ge 8 && ${CPU_CORES} -lt 12 && ${RAM_TOTAL} -gt 4194304 ]]; then
PM_MAX_CHILDREN=$((CPU_CORES * 6))
PM_MAX_REQUEST=2000
elif [[ ${CPU_CORES} -ge 13 && ${CPU_CORES} -lt 16 && ${RAM_TOTAL} -gt 4194304 ]]; then
PM_MAX_CHILDREN=$((CPU_CORES * 6))
PM_MAX_REQUEST=2000
elif [[ ${CPU_CORES} -ge 17 && ${RAM_TOTAL} -gt 4194304 ]]; then
PM_MAX_CHILDREN=$((CPU_CORES * 5))
PM_MAX_REQUEST=2000
else
PM_MAX_CHILDREN=$((CPU_CORES * 5))
PM_MAX_REQUEST=500
fi
}
mariadb_calculation() {
if [[ ${RAM_TOTAL} -gt 400000 && ${RAM_TOTAL} -le 2099152 ]]; then #1GB Ram
max_allowed_packet="32M"
back_log="100"
max_connections="150"
key_buffer_size="32M"
myisam_sort_buffer_size="32M"
myisam_max_sort_file_size="2048M"
innodb_log_buffer_size="8M"
join_buffer_size="64K"
read_buffer_size="64K"
sort_buffer_size="128K"
table_definition_cache="4096"
table_open_cache="2048"
thread_cache_size="64"
tmp_table_size="32M"
max_heap_table_size="32M"
query_cache_limit="512K"
query_cache_size="16M"
innodb_open_files="2000"
innodb_buffer_pool_size="48M"
innodb_io_capacity="100"
aria_pagecache_buffer_size="8M"
aria_sort_buffer_size="8M"
net_buffer_length="8192"
read_rnd_buffer_size="256K"
innodb_log_file_size="128M"
innodb_read_io_threads="2"
aria_log_file_size="32M"
key_buffer="32M "
sort_buffer="16M"
read_buffer="16M"
write_buffer="16M"
fi
if [[ ${RAM_TOTAL} -gt 2099152 && ${RAM_TOTAL} -le 4198304 ]]; then #2GB Ram
max_allowed_packet="48M"
back_log="200"
max_connections="200"
key_buffer_size="32M"
myisam_sort_buffer_size="64M"
myisam_max_sort_file_size="2048M"
innodb_log_buffer_size="8M"
join_buffer_size="128K"
read_buffer_size="128K"
sort_buffer_size="256K"
table_definition_cache="8192"
table_open_cache="4096"
thread_cache_size="128"
tmp_table_size="128M"
max_heap_table_size="128M"
query_cache_limit="1024K"
query_cache_size="64M"
innodb_open_files="4000"
innodb_buffer_pool_size="192M"
innodb_io_capacity="200"
aria_pagecache_buffer_size="32M"
aria_sort_buffer_size="32M"
net_buffer_length="8192"
read_rnd_buffer_size="256K"
innodb_log_file_size="128M"
innodb_read_io_threads="2"
aria_log_file_size="32M"
key_buffer="32M "
sort_buffer="16M"
read_buffer="16M"
write_buffer="16M"
fi
if [[ ${RAM_TOTAL} -gt 4198304 && ${RAM_TOTAL} -le 8396608 ]]; then #4GB Ram
max_allowed_packet="64M"
back_log="200"
max_connections="350"
key_buffer_size="256M"
myisam_sort_buffer_size="256M"
myisam_max_sort_file_size="2048M"
innodb_log_buffer_size="8M"
join_buffer_size="256K"
read_buffer_size="256K"
sort_buffer_size="256K"
table_definition_cache="8192"
table_open_cache="4096"
thread_cache_size="256"
tmp_table_size="256M"
max_heap_table_size="256M"
query_cache_limit="1024K"
query_cache_size="80M"
innodb_open_files="4000"
innodb_buffer_pool_size="512M"
innodb_io_capacity="300"
aria_pagecache_buffer_size="64M"
aria_sort_buffer_size="64M"
net_buffer_length="16384"
read_rnd_buffer_size="512K"
innodb_log_file_size="256M"
innodb_read_io_threads="4"
aria_log_file_size="64M"
key_buffer="256M "
sort_buffer="32M"
read_buffer="32M"
write_buffer="32M"
fi
if [[ ${RAM_TOTAL} -gt 8396608 && ${RAM_TOTAL} -le 16793216 ]]; then #8GB Ram
max_allowed_packet="64M"
back_log="512"
max_connections="400"
key_buffer_size="384M"
myisam_sort_buffer_size="256M"
myisam_max_sort_file_size="2048M"
innodb_log_buffer_size="16M"
join_buffer_size="256K"
read_buffer_size="256K"
sort_buffer_size="512K"
table_definition_cache="8192"
table_open_cache="8192"
thread_cache_size="256"
tmp_table_size="512M"
max_heap_table_size="512M"
query_cache_limit="1024K"
query_cache_size="128M"
innodb_open_files="8000"
innodb_buffer_pool_size="1024M"
innodb_io_capacity="400"
aria_pagecache_buffer_size="64M"
aria_sort_buffer_size="64M"
net_buffer_length="16384"
read_rnd_buffer_size="512K"
innodb_log_file_size="384M"
innodb_read_io_threads="4"
aria_log_file_size="64M"
key_buffer="384M "
sort_buffer="64M"
read_buffer="64M"
write_buffer="64M"
fi
if [[ ${RAM_TOTAL} -gt 16793216 && ${RAM_TOTAL} -le 33586432 ]]; then #16GB Ram
max_allowed_packet="64M"
back_log="768"
max_connections="500"
key_buffer_size="512M"
myisam_sort_buffer_size="512M"
myisam_max_sort_file_size="4096M"
innodb_log_buffer_size="32M"
join_buffer_size="1M"
read_buffer_size="1M"
sort_buffer_size="2M"
table_definition_cache="10240"
table_open_cache="10240"
thread_cache_size="384"
tmp_table_size="768M"
max_heap_table_size="768M"
query_cache_limit="1024K"
query_cache_size="160M"
innodb_open_files="10000"
innodb_buffer_pool_size="4096M"
innodb_io_capacity="500"
aria_pagecache_buffer_size="128M"
aria_sort_buffer_size="128M"
net_buffer_length="16384"
read_rnd_buffer_size="512K"
innodb_log_file_size="640M"
innodb_read_io_threads="4"
aria_log_file_size="64M"
key_buffer="768M "
sort_buffer="128M"
read_buffer="128M"
write_buffer="128M"
fi
if [[ "$(expr "${RAM_TOTAL}" \>= 33586432)" == "1" ]]; then #32GB Ram
max_allowed_packet="64M"
back_log="1024"
max_connections="600"
key_buffer_size="768M"
myisam_sort_buffer_size="768M"
myisam_max_sort_file_size="8192M"
innodb_log_buffer_size="64M"
join_buffer_size="2M"
read_buffer_size="2M"
sort_buffer_size="2M"
table_definition_cache="10240"
table_open_cache="10240"
thread_cache_size="384"
tmp_table_size="1024M"
max_heap_table_size="1024M"
query_cache_limit="1536K"
query_cache_size="256M"
innodb_open_files="10000"
innodb_buffer_pool_size="8192M"
innodb_io_capacity="600"
aria_pagecache_buffer_size="128M"
aria_sort_buffer_size="128M"
net_buffer_length="16384"
read_rnd_buffer_size="512K"
innodb_log_file_size="768M"
innodb_read_io_threads="4"
aria_log_file_size="64M"
key_buffer="1024M "
sort_buffer="256M"
read_buffer="256M"
write_buffer="256M"
fi
if [[ "$(expr "${RAM_TOTAL}" \>= 64000000)" == "1" ]]; then #64GB Ram
max_allowed_packet="80M"
back_log="1024"
max_connections="800"
key_buffer_size="1024M"
myisam_sort_buffer_size="1024M"
myisam_max_sort_file_size="10240M"
innodb_log_buffer_size="64M"
join_buffer_size="2M"
read_buffer_size="2M"
sort_buffer_size="2M"
table_definition_cache="10240"
table_open_cache="10240"
thread_cache_size="384"
tmp_table_size="1536M"
max_heap_table_size="1536M"
query_cache_limit="1536K"
query_cache_size="256M"
innodb_open_files="10000"
innodb_buffer_pool_size="12288M"
innodb_io_capacity="800"
aria_pagecache_buffer_size="256M"
aria_sort_buffer_size="256M"
net_buffer_length="16384"
read_rnd_buffer_size="512K"
innodb_log_file_size="1024M"
innodb_read_io_threads="4"
aria_log_file_size="128M"
key_buffer="1536M "
sort_buffer="384M"
read_buffer="384M"
write_buffer="384M"
fi
}
############################################
# Install Other Library
############################################
install_optipng(){
optipng_version=$(curl -s ${UPDATE_LINK}/version | grep "optipng_version=" | cut -f2 -d'=')
cd_dir /opt
wget -O- http://scripts.hostvn.net/modules/optipng-"${optipng_version}".tar.gz | tar -xz
cd_dir optipng-"${optipng_version}"
./configure
make
cp /opt/optipng-"${optipng_version}"/src/optipng/optipng /usr/bin/
cd_dir /opt
rm -rf /opt/optipng-"${optipng_version}"
}
install_jpegoptim(){
jpegoptim_version=$(curl -s ${UPDATE_LINK}/version | grep "jpegoptim_version=" | cut -f2 -d'=')
cd_dir /opt
wget -O- http://scripts.hostvn.net/modules/jpegoptim-RELEASE."${jpegoptim_version}".tar.gz | tar -xz
cd_dir jpegoptim-RELEASE."${jpegoptim_version}"
./configure
make && make strip && make install
ln -s /usr/local/bin/jpegoptim /usr/bin/jpegoptim
cd_dir /opt
rm -rf /opt/jpegoptim-RELEASE."${jpegoptim_version}"
}
install_pngquant(){
cd_dir /opt
git clone --recursive https://github.com/kornelski/pngquant.git
cd_dir /opt/pngquant
./configure
make && make install
cd_dir "${DIR}"
rm -rf /opt/pngquant
}
############################################
# Config LEMP
############################################
# Config SSL
self_signed_ssl() {
#Create dhparams
self_signed_dir="/etc/nginx/ssl/server"
mkdir -p "${self_signed_dir}"
openssl dhparam -out /etc/nginx/ssl/dhparams.pem 2048
openssl genrsa -out "${self_signed_dir}/server.key" 4096
openssl req -new -key "${self_signed_dir}/server.key" \
-out "${self_signed_dir}/server.csr" -subj "/C=VN/ST=Caugiay/L=Hanoi/O=Hostvn/OU=IT Department/CN=${IPADDRESS}"
openssl x509 -in "${self_signed_dir}/server.csr" -out "${self_signed_dir}/server.crt" \
-req -signkey "${self_signed_dir}/server.key" -days 3650
}
# Config Nginx
create_nginx_conf() {
mkdir -p /etc/nginx/alias
mkdir -p /etc/nginx/redirect
mkdir -p /etc/nginx/php
mkdir -p /etc/nginx/conf.d
mkdir -p /etc/nginx/pagespeed
mkdir -p /usr/share/nginx/html/
chown -R nginx. /usr/share/nginx/html/
mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf."$(date +%Y-%m-%d)"
cat >>"/etc/nginx/nginx.conf" <<EONGINXCONF
user nginx;
worker_processes auto;
worker_rlimit_nofile 260000;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections ${MAX_CLIENT};
accept_mutex off;
accept_mutex_delay 200ms;
use epoll;
#multi_accept on;
}
http {
index index.html index.htm index.php;
include /etc/nginx/mime.types;
default_type application/octet-stream;
charset utf-8;
log_format main '\$remote_addr - \$remote_user [\$time_local] "\$request" '
'\$status \$body_bytes_sent "\$http_referer" '
'"\$http_user_agent" "\$http_x_forwarded_for"';
access_log off;
server_tokens off;
sendfile on;
tcp_nopush on;
tcp_nodelay off;
types_hash_max_size 2048;
server_names_hash_bucket_size 128;
server_names_hash_max_size 10240;
client_max_body_size 1024m;
client_body_buffer_size 128k;
client_body_in_file_only off;
client_body_timeout 60s;
client_header_buffer_size 256k;
client_header_timeout 20s;
large_client_header_buffers 8 256k;
keepalive_timeout 15;
keepalive_disable msie6;
reset_timedout_connection on;
send_timeout 60s;
disable_symlinks if_not_owner from=\$document_root;
server_name_in_redirect off;
open_file_cache max=2000 inactive=20s;
open_file_cache_valid 120s;
open_file_cache_min_uses 2;
open_file_cache_errors off;
# Limit Request
limit_req_status 403;
# limit the number of connections per single IP
limit_conn_zone \$binary_remote_addr zone=conn_limit_per_ip:10m;
# limit the number of requests for a given session
limit_req_zone \$binary_remote_addr zone=req_limit_per_ip:10m rate=1r/s;
# Custom Response Headers
more_set_headers 'Server: HOSTVN.NET';
more_set_headers 'X-Content-Type-Options "nosniff" always';
more_set_headers 'X-XSS-Protection "1; mode=block" always';
more_set_headers 'Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always';
# Custom Variables
map \$scheme \$https_suffix { default ''; https '-https'; }
include /etc/nginx/extra/nginx_cache.conf;
include /etc/nginx/extra/gzip.conf;
include /etc/nginx/extra/brotli.conf;
include /etc/nginx/extra/ssl.conf;
include /etc/nginx/extra/cloudflare.conf;
include /etc/nginx/web_apps.conf;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/redirect/*.conf;
}
EONGINXCONF
}
_create_mod_security_config(){
mkdir -p /etc/nginx/modsec
cp /usr/share/nginx_module/ModSecurity/modsecurity.conf-recommended /etc/nginx/modsec/modsecurity.conf
cp /usr/share/nginx_module/ModSecurity/unicode.mapping /etc/nginx/modsec
sed -i 's/SecRuleEngine DetectionOnly/SecRuleEngine On/' /etc/nginx/modsec/modsecurity.conf
rm -rf /etc/nginx/modsec/main.conf
cat >> "/etc/nginx/modsec/main.conf" << EOmodsec_main
include /etc/nginx/modsec/modsecurity.conf
include /etc/nginx/owasp-modsecurity-crs/crs-setup.conf
include /etc/nginx/owasp-modsecurity-crs/rules/*.conf
EOmodsec_main
git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git
cd_dir owasp-modsecurity-crs
mv crs-setup.conf.example crs-setup.conf
cd_dir rules
mv RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
cd_dir "${DIR}"
}
create_wordpress_conf() {
mkdir -p /etc/nginx/wordpress
cat >>"/etc/nginx/wordpress/disable_xmlrpc.conf" <<EOxmlrpc
# Disable XML-RPC
location = /xmlrpc.php { deny all; access_log off; log_not_found off; }
EOxmlrpc
cat >>"/etc/nginx/wordpress/disable_user_api.conf" <<EOuser_api
#Block API User
location ~* /wp-json/wp/v2/users {
allow 127.0.0.1;
deny all;
access_log off;
log_not_found off;
}
EOuser_api
cat >> "/etc/nginx/wordpress/webp_express.conf" << EOwebp_express
# WebP Express rules
location ~* ^/?wp-content/.*\.(png|jpe?g)$ {
add_header Vary Accept;
expires 365d;
if (\$http_accept !~* "webp"){
break;
}
try_files
/wp-content/webp-express/webp-images/doc-root/\$uri.webp
\$uri.webp
/wp-content/plugins/webp-express/wod/webp-on-demand.php?xsource=x\$request_filename&wp-content=wp-content
;
}
# Route requests for non-existing webps to the converter
location ~* ^/?wp-content/.*\.(png|jpe?g)\.webp$ {
try_files
\$uri
/wp-content/plugins/webp-express/wod/webp-realizer.php?xdestination=x\$request_filename&wp-content=wp-content
;
}
# (WebP Express rules ends here)
EOwebp_express
cat >>"/etc/nginx/wordpress/wordpress_secure.conf" <<EOwpsecure
rewrite /wp-admin$ \$scheme://\$host\$uri/ permanent;
location /wp-includes/{
location ~ \.(gz|tar|bzip2|7z|php|php5|php7|log|error|py|pl|kid|love|cgi)\$ { deny all; }
}
location /wp-content/uploads {
location ~ \.(gz|tar|bzip2|7z|php|php5|php7|log|error|py|pl|kid|love|cgi)\$ { deny all; }
}
location /wp-content/updraft { deny all; access_log off; log_not_found off; }
location /wp-content/backups-dup-pro { deny all; access_log off; log_not_found off; }
location /wp-snapshots { deny all; access_log off; log_not_found off; }
location /wp-content/uploads/sucuri { deny all; access_log off; log_not_found off; }
location /wp-content/uploads/nginx-helper { deny all; access_log off; log_not_found off; }
location = /wp-config.php { deny all; access_log off; log_not_found off; }
location = /wp-links-opml.php { deny all; access_log off; log_not_found off; }
location = /wp-config-sample.php { deny all; access_log off; log_not_found off; }
location = /readme.html { deny all; access_log off; log_not_found off; }
location = /license.txt { deny all; access_log off; log_not_found off; }
# enable gzip on static assets - php files are forbidden
location /wp-content/cache {
# Cache css & js files
location ~* \.(?:css(\.map)?|js(\.map)?|.html)\$ {
add_header Access-Control-Allow-Origin *;
access_log off;
log_not_found off;
expires 365d;
}
location ~ \.php\$ { deny all; access_log off; log_not_found off; }
}
EOwpsecure
cat >>"/etc/nginx/wordpress/yoast_seo.conf" <<EOyoast_seo
#Yoast SEO Sitemaps
location ~* ^/wp-content/plugins/wordpress-seo(?:-premium)?/css/main-sitemap\.xsl\$ {}
location ~ ([^/]*)sitemap(.*).x(m|s)l\$ {
## this rewrites sitemap.xml to /sitemap_index.xml
rewrite ^/sitemap.xml\$ /sitemap_index.xml permanent;
## this makes the XML sitemaps work
rewrite ^/([a-z]+)?-?sitemap.xsl\$ /index.php?yoast-sitemap-xsl=\$1 last;
rewrite ^/sitemap_index.xml\$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml\$ /index.php?sitemap=\$1&sitemap_n=\$2 last;
## The following lines are optional for the premium extensions
## News SEO
rewrite ^/news-sitemap.xml\$ /index.php?sitemap=wpseo_news last;
## Local SEO
rewrite ^/locations.kml\$ /index.php?sitemap=wpseo_local_kml last;
rewrite ^/geo-sitemap.xml\$ /index.php?sitemap=wpseo_local last;
## Video SEO
rewrite ^/video-sitemap.xsl\$ /index.php?yoast-sitemap-xsl=video last;
}
EOyoast_seo
cat >>"/etc/nginx/wordpress/rank_math_seo.conf" <<EOrank_math_seo