-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnextcloud.sh
1461 lines (1254 loc) · 51.6 KB
/
nextcloud.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
###########################################
# CentOS 7 NextCloud Install Shell Script #
###########################################
scriptpath=$(pwd)
clear
echo "+-----------------------------------------------------------------------------------------+"
echo "| Centos 7 Nextcloud Install Shell Script |"
echo "+-----------------------------------------------------------------------------------------+"
echo "| A tool to auto-compile & install nextcloud on linux |"
echo "+-----------------------------------------------------------------------------------------+"
echo "| This script can install Nextcloud services and 2 office components that can be matched. |"
echo "+-----------------------------------------------------------------------------------------+"
# System check
init_system() {
# Replacement system CentOS-Base repo
cat >/etc/yum.repos.d/CentOS-Base.repo <<"EOF"
# CentOS-Base.repo
# disable metalink enable baseurl
# baseurl default connection address
# http://mirror.centos.org/centos/
[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
EOF
# check selinux
selinuxstate=$(getenforce)
if [ ${selinuxstate} != "Disabled" ] ; then
setenforce 0
echo -e "Permanently shutdown SELINUX function"
sed -i 's/SELINUX\=enforcing/SELINUX\=disabled/g' /etc/selinux/config
fi
}
# Mysql select version
mysql_config() {
echo -e "\nMySQL configuration"
db_info=('MySQL 5.7' 'MySQL 8.0')
if [ -z ${dbselect} ]; then
dbselect="1"
echo "Please select MySQL version."
echo "1: Install ${db_info[0]} (Default)"
echo "2: Install ${db_info[1]}"
read -p "Enter your choice (1 , 2): " dbselect
fi
case "${dbselect}" in
1)
echo "You will install ${db_info[0]}"
;;
2)
echo "You will install ${db_info[1]}"
;;
*)
echo "No input,You will install ${db_info[0]}"
dbselect="1"
esac
read -p "Please enter the MySQL root Password: " newmysqlpassword
}
# Nextcloud config info
nextcloud_config() {
echo -e "\nNextcloud configuration"
read -p "Please enter the nextcloud admin account: " nextclouduser
read -p "Please enter the nextcloud admin password: " nextcloudpassword
read -p "Please enter the nextcloud database password: " nextcloudmysqlpassword
read -p "Please enter the nextcloud binding domain name: " nextclouddomainname
read -p "Please enter the nextcloud version (example: 14.0.1): " nextcloudversion
echo -e "\nNextcloud SSL configuration"
echo -e "Please put certificate files and key files in the same directory as the script."
read -p "Please enter the certificate file full name (example: nextcloud.crt): " nextcloudcertname
read -p "Please enter the certificate key file full name(example: nextcloud.key): " nextcloudcertkeyname
if [ -z ${mailselect} ]; then
mailselect="1"
echo -e "\nPlease select enable qq e-mail function."
echo "1: Yes, the configuration function (Default)"
echo "2: No, no configuration function"
read -p "Enter your choice (1 , 2): " mailselect
fi
case "${mailselect}" in
1)
echo "yes configuration function"
;;
2)
echo "no configuration function"
;;
*)
echo "No input,Default values will be used"
mailselect="1"
esac
if [ ${mailselect} = "1" ] ; then
echo -e "\nOnly QQ mail is supported."
echo -e "The password of the mailbox needs to be set up to generate the authorization code.\r"
read -p "Please enter the mail address (example: [email protected]): " mailaddress
read -p "Please enter the mail password (example: 23123545646): " mailpassword
fi
}
# office soft select
officesoft_config() {
if [ -z ${officeselect} ]; then
officeselect="0"
echo -e "\nPlease select office install mode."
echo "1: Install linux for onlyoffice."
echo "2: Install docker for onlyoffice."
echo "3: Install linux for collaboraoffice."
echo "4: Install docker for collaboraoffice."
echo "0: Do not Install office software (default)"
read -p "Enter your choice (1 , 2 , 3 , 4 or 0): " officeselect
fi
case "${officeselect}" in
0)
echo "do not Install office soft."
;;
1)
echo "Install linux for onlyoffice."
;;
2)
echo "Install docker for onlyoffice."
;;
3)
echo "Install linux for collaboraoffice."
;;
4)
echo "Install docker for collaboraoffice."
;;
*)
echo "No input,Default values will be used"
officeselect="0"
esac
# office binding domain name
if [[ "${officeselect}" =~ ^[1234]$ ]] ; then
read -p "Please enter the office binding domain name: " officedomainname
echo -e "Please put certificate files and key files in the same directory as the script."
read -p "Please enter the certificate file full name (example: office.crt): " officecertname
read -p "Please enter the certificate key file full name(example: office.key): " officecertkeyname
fi
# onlyoffice secret and database password
if [[ "${officeselect}" =~ ^[1]$ ]] ; then
read -p "Please enter the onlyoffice secret password: " onlyofficesecret
read -p "Please enter the onlyoffice database password: " onlyofficepassword
fi
if [[ "${officeselect}" =~ ^[2]$ ]] ; then
read -p "Please enter the onlyoffice secret password: " onlyofficesecret
fi
# collaboraonline web user password
if [[ "${officeselect}" =~ ^[34]$ ]] ; then
read -p "Please enter the collaboraoffice admin account: " collaboraofficename
read -p "Please enter the collaboraoffice admin password: " collaboraofficepassword
fi
}
mysql_nextcloud() {
cat >/tmp/nextcloud.sql <<EOF
create database if not exists nextcloud;
create user nextcloud@localhost identified by '$nextcloudmysqlpassword';
grant all privileges on nextcloud.* to nextcloud@localhost;
flush privileges;
exit
EOF
mysql -u root -p$newmysqlpassword < /tmp/nextcloud.sql
rm -f /tmp/nextcloud.sql
}
nextcloud_redis() {
sed -i '$d' /opt/nextcloud/config/config.php
cat >>/opt/nextcloud/config/config.php <<"EOF"
'filelocking.enabled' => true,
'memcache.local' => '\OC\Memcache\APCu',
'memcache.locking' => '\OC\Memcache\Redis',
'memcache.distributed' => '\OC\Memcache\Redis',
'redis' => array(
'host' => 'localhost',
'port' => 6379,
),
);
EOF
}
mysql_password() {
cat > modifymysqlpassword.exp <<EOF
#!/usr/bin/expect
set timeout 30
set password $mysqlpassword
set newpassword $newmysqlpassword
spawn mysql_secure_installation
expect "Enter password" {send "\$password\r";}
expect "New password" {send "\$newpassword\r";}
expect "Re-enter new password" {send "\$newpassword\r";}
expect "Do you wish to continue with the password provided" {send "y\r";}
expect "Change the password" {send "\r";}
expect "Remove anonymous users" {send "y\r";}
expect "Disallow root login remotely" {send "y\r";}
expect "Remove test database and access" {send "y\r";}
expect "Reload privilege tables now" {send "y\r";}
expect eof
EOF
}
onlyoffice_config() {
cat > onlyofficeconfig.exp <<EOF
#!/usr/bin/expect
set timeout 60
set password $onlyofficepassword
spawn bash documentserver-configure.sh
expect "Host" {send "localhost\r";}
expect "Database name" {send "onlyoffice\r";}
expect "User" {send "onlyoffice\r";}
expect "Password" {send "\$password\r";}
expect "Host" {send "localhost\r";}
expect "Host" {send "localhost\r";}
expect "User" {send "guest\r";}
expect "Password" {send "guest\r";}
expect eof
EOF
}
self_certificate() {
cat >/etc/nginx/cert/root.crt <<"EOF"
-----BEGIN CERTIFICATE-----
MIIDdzCCAl+gAwIBAgIJALIG4MqPPPyZMA0GCSqGSIb3DQEBCwUAMFIxCzAJBgNV
BAYTAkNOMQ4wDAYDVQQIDAVDaGluYTEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRww
GgYDVQQKDBNEZWZhdWx0IENvbXBhbnkgTHRkMB4XDTE3MDkyMjA4MzcyMVoXDTE4
MDkyMjA4MzcyMVowUjELMAkGA1UEBhMCQ04xDjAMBgNVBAgMBUNoaW5hMRUwEwYD
VQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0RlZmF1bHQgQ29tcGF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oRGg3Fz/taGACud3iA731eXYIg2MG1kdYi7vufeJPZyx1l5sQyjZ6vAxdOXB
kcdCpfCTTzeob7JeVBPzqNzSCM8uYHeEmCZB2+nrqBp75lth6W9leGBqDFcCgYAc
YJQ00vI1uBbg0FLvOY9uMEoE1P5cUZJ/+Z17xJZc7gcoFxj+3uwCTIjjuxUgy0Kr
PHR9RqW4rMkMZleWvDyjhYpMYsmqgUR+lOJBP2Hn8aTPJqLwBD8Xb3JmIhIdduHx
gk3fFuR0KajuLZzRW55dH3DS8SPv7dMXmTIx8e7eXQKBgAUb26yJ+QT3FjOF7UVv
yluV7auwrVcGRhhF9XIpn9orYVRPcQY4gY2wqF1gYhHnz5VIWmXKxfDd7ZaPtx8L
UaF83K4cdQiD27YhnnVSBhygAbXhfui4acwQM5j6iuDyuSWWlaAiX+/Ac35gsLuk
r1DFDASTgBIecibWrId2vz5A
-----END PRIVATE KEY-----
EOF
}
nginx_repo() {
cat >/etc/yum.repos.d/nginx.repo <<"EOF"
# nginx.repo
# baseurl default connection address
# http://nginx.org/packages/centos/7/$basearch/
[nginx]
name=nginx repo
baseurl=https://mirrors.0diis.com/nginx/centos/7/$basearch/
gpgcheck=0
enabled=1
EOF
}
epel_repo() {
cat >/etc/yum.repos.d/epel.repo <<"EOF"
# epel.repo
# disable metalink enable baseurl
# baseurl default connection address
# http://download.fedoraproject.org/pub/epel/7/
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1
EOF
}
webtatic_repo() {
cat >/etc/yum.repos.d/webtatic.repo <<"EOF"
# webtatic.repo
# disable metalink enable baseurl
# baseurl default connection address
# https://repo.webtatic.com/yum/el7/
[webtatic]
name=Webtatic Repository EL7 - $basearch
baseurl=https://mirrors.0diis.com/webtatic/el7/$basearch/
#mirrorlist=https://mirror.webtatic.com/yum/el7/$basearch/mirrorlist
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el7
[webtatic-debuginfo]
name=Webtatic Repository EL7 - $basearch - Debug
baseurl=https://mirrors.0diis.com/webtatic/el7/$basearch/debug/
#mirrorlist=https://mirror.webtatic.com/yum/el7/$basearch/debug/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el7
[webtatic-source]
name=Webtatic Repository EL7 - $basearch - Source
baseurl=https://mirrors.0diis.com/webtatic/el7/SRPMS/
#mirrorlist=https://mirror.webtatic.com/yum/el7/SRPMS/mirrorlist
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-webtatic-el7
EOF
}
mysql_repo() {
cat >/etc/yum.repos.d/mysql-community.repo <<"EOF"
# mysql-community.repo
# baseurl default connection address http://repo.mysql.com/yum/
[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=https://mirrors.0diis.com/mysql/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-community]
name=MySQL Tools Community
baseurl=https://mirrors.0diis.com/mysql/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=https://mirrors.0diis.com/mysql/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=https://mirrors.0diis.com/mysql/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=https://mirrors.0diis.com/mysql/mysql-5.7-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 8.0
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=https://mirrors.0diis.com/mysql/mysql-8.0-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-tools-preview]
name=MySQL Tools Preview
baseurl=https://mirrors.0diis.com/mysql/mysql-tools-preview/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-cluster-7.5-community]
name=MySQL Cluster 7.5 Community
baseurl=https://mirrors.0diis.com/mysql/mysql-cluster-7.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql-cluster-7.6-community]
name=MySQL Cluster 7.6 Community
baseurl=https://mirrors.0diis.com/mysql/mysql-cluster-7.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
EOF
}
nodejs_repo() {
cat >/etc/yum.repos.d/nodesource.repo <<"EOF"
# nodesource.repo
# baseurl default connection address
# https://rpm.nodesource.com/pub_8.x/el/7/$basearch
[nodesource]
name=Node.js Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_8.x/el/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
[nodesource-source]
name=Node.js for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/nodesource/rpm_8.x/el/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/NODESOURCE-GPG-SIGNING-KEY-EL
gpgcheck=1
EOF
}
onlyoffice_repo() {
cat >/etc/yum.repos.d/onlyoffice.repo <<"EOF"
# onlyoffice.repo
# baseurl default connection address
# http://download.onlyoffice.com/repo/centos/main/noarch/
[onlyoffice]
name=onlyoffice repo
baseurl=https://mirrors.0diis.com/onlyoffice/centos/main/noarch/
gpgcheck=1
enabled=1
EOF
}
collaboraoffice_repo() {
cat >/etc/yum.repos.d/collaboraoffice.repo <<"EOF"
# collaboraoffice.repo
# baseurl default connection address
# https://collaboraoffice.com/repos/CollaboraOnline/CODE-centos7
[collaboraoffice]
name=collaboraoffice repo
baseurl=https://mirrors.0diis.com/collaboraoffice/CollaboraOnline/CODE-centos7
enabled=1
EOF
}
nginx_onlyoffice() {
cat >/etc/nginx/conf.d/onlyoffice.conf <<"EOF"
include /etc/nginx/includes/onlyoffice-http.conf;
## Normal HTTP host
server {
listen 80;
listen [::]:80;
server_name officedomainname;
# Lets Encrypt SSL Certificate Directory
location /.well-known/acme-challenge/ {
root /opt/onlyoffice/; # Specify here where the challenge file is placed
}
# Tencent Cloud SSL Certificate Directory
location /.well-known/pki-validation/ {
root /opt/onlyoffice/; # Specify here where the challenge file is placed
}
# enforce https
return 301 https://$server_name$request_uri;
}
## HTTP host for internal services
# server {
# listen 127.0.0.1:80;
# listen [::1]:80;
# server_name localhost;
# server_tokens off;
# include /etc/nginx/includes/onlyoffice-documentserver-common.conf;
# include /etc/nginx/includes/onlyoffice-documentserver-docservice.conf;
# }
## HTTPS host
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name officedomainname;
# server_tokens off;
root /usr/share/nginx/html;
## Strong SSL Security
## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
ssl on;
ssl_certificate /etc/nginx/cert/officecertname;
ssl_certificate_key /etc/nginx/cert/officecertkeyname;
ssl_verify_client off;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_prefer_server_ciphers on;
add_header Strict-Transport-Security max-age=31536000;
# add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
## [Optional] If your certficate has OCSP, enable OCSP stapling to reduce the overhead and latency of running SSL.
## Replace with your ssl_trusted_certificate. For more info see:
## - https://medium.com/devops-programming/4445f4862461
## - https://www.ruby-forum.com/topic/4419319
## - https://www.digitalocean.com/community/tutorials/how-to-configure-ocsp-stapling-on-apache-and-nginx
# ssl_stapling on;
# ssl_stapling_verify on;
# ssl_trusted_certificate /etc/nginx/ssl/stapling.trusted.crt;
# resolver 208.67.222.222 208.67.222.220 valid=300s; # Can change to your DNS resolver if desired
# resolver_timeout 10s;
## [Optional] Generate a stronger DHE parameter:
## cd /etc/ssl/certs
## sudo openssl dhparam -out dhparam.pem 4096
##
# ssl_dhparam /etc/ssl/certs/dhparam.pem;
include /etc/nginx/includes/onlyoffice-documentserver-*.conf;
}
EOF
}
nginx_onlyoffice_docker() {
cat >/etc/nginx/conf.d/onlyoffice.conf <<"EOF"
server {
listen 80;
listen [::]:80;
server_name officedomainname;
# Lets Encrypt SSL Certificate Directory
location /.well-known/acme-challenge/ {
root /opt/onlyoffice/; # Specify here where the challenge file is placed
}
# Tencent Cloud SSL Certificate Directory
location /.well-known/pki-validation/ {
root /opt/onlyoffice/; # Specify here where the challenge file is placed
}
# enforce https
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name officedomainname;
ssl_certificate /etc/nginx/cert/officecertname;
ssl_certificate_key /etc/nginx/cert/officecertkeyname;
ssl_prefer_server_ciphers on;
location / {
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://localhost:8000;
}
}
EOF
}
nginx_collaboraoffice() {
cat >/etc/nginx/conf.d/collaboraoffice.conf <<"EOF"
server {
listen 80;
listen [::]:80;
server_name officedomainname;
# Lets Encrypt SSL Certificate Directory
location /.well-known/acme-challenge/ {
root /opt/collaboraoffice/; # Specify here where the challenge file is placed
}
# Tencent Cloud SSL Certificate Directory
location /.well-known/pki-validation/ {
root /opt/collaboraoffice/; # Specify here where the challenge file is placed
}
# enforce https
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name officedomainname;
ssl_certificate /etc/nginx/cert/officecertname;
ssl_certificate_key /etc/nginx/cert/officecertkeyname;
ssl_prefer_server_ciphers on;
# static files
location ^~ /loleaflet {
proxy_pass https://localhost:9980;
proxy_set_header Host $http_host;
}
# WOPI discovery URL
location ^~ /hosting/discovery {
proxy_pass https://localhost:9980;
proxy_set_header Host $http_host;
}
# main websocket
location ~ ^/lool/(.*)/ws$ {
proxy_pass https://localhost:9980;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host;
proxy_read_timeout 36000s;
}
# download, presentation and image upload
location ~ ^/lool {
proxy_pass https://localhost:9980;
proxy_set_header Host $http_host;
}
# Admin Console websocket
location ^~ /lool/adminws {
proxy_pass https://localhost:9980;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $http_host;
proxy_read_timeout 36000s;
}
}
EOF
}
nginx_nextcloud() {
cat >/etc/nginx/conf.d/nextcloud.conf <<"EOF"
upstream php-handler {
server 127.0.0.1:9000;
# Depending on your used PHP version
#server unix:/var/run/php5-fpm.sock;
#server unix:/var/run/php7-fpm.sock;
}
server {
listen 80;
listen [::]:80;
server_name nextclouddomainname;
# Lets Encrypt SSL Certificate Directory
location /.well-known/acme-challenge/ {
root /opt/nextcloud/; # Specify here where the challenge file is placed
}
# Tencent Cloud SSL Certificate Directory
location /.well-known/pki-validation/ {
root /opt/nextcloud/; # Specify here where the challenge file is placed
}
# enforce https
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name nextclouddomainname;
# Use Mozilla's guidelines for SSL/TLS settings
# https://mozilla.github.io/server-side-tls/ssl-config-generator/
# NOTE: some settings below might be redundant
ssl_certificate /etc/nginx/cert/nextcloudcertname;
ssl_certificate_key /etc/nginx/cert/nextcloudcertkeyname;
ssl_prefer_server_ciphers on;
# Add headers to serve security related headers
# Before enabling Strict-Transport-Security headers please read into this
# topic first.
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
# Remove X-Powered-By, which is an information leak
fastcgi_hide_header X-Powered-By;
# Path to the root of your installation
root /opt/nextcloud/;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# The following 2 rules are only needed for the user_webfinger app.
# Uncomment it if you're planning to use this app.
#rewrite ^/.well-known/host-meta /public.php?service=host-meta last;
#rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json
# last;
location = /.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = /.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
# set max upload size
client_max_body_size 20480M;
# set Cache Configuration
fastcgi_buffers 128 256k;
fastcgi_buffer_size 1024k;
client_body_buffer_size 1024k;
# Enable gzip but do not remove ETag headers
gzip on;
gzip_vary on;
gzip_comp_level 4;
gzip_min_length 256;
gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;
# Uncomment if your server is build with the ngx_pagespeed module
# This module is currently not supported.
#pagespeed off;
location / {
rewrite ^ /index.php$request_uri;
}
location ~ ^/(?:build|tests|config|lib|3rdparty|templates|data)/ {
deny all;
}
location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) {
deny all;
}
location ~ ^/(?:index|remote|public|cron|core/ajax/update|status|ocs/v[12]|updater/.+|ocs-provider/.+)\.php(?:$|/) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param HTTPS on;
#Avoid sending the security headers twice
fastcgi_param modHeadersAvailable true;
fastcgi_param front_controller_active true;
fastcgi_pass php-handler;
fastcgi_send_timeout 3600s;
fastcgi_read_timeout 3600s;
fastcgi_connect_timeout 3600s;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
location ~ ^/(?:updater|ocs-provider)(?:$|/) {
try_files $uri/ =404;
index index.php;
}
# Adding the cache control header for js and css files
# Make sure it is BELOW the PHP block
location ~ \.(?:css|js|woff|svg|gif)$ {
try_files $uri /index.php$request_uri;
add_header Cache-Control "public, max-age=15778463";
# Add headers to serve security related headers (It is intended to
# have those duplicated to the ones above)
# Before enabling Strict-Transport-Security headers please read into
# this topic first.
# add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;";
#
# WARNING: Only add the preload option once you read about
# the consequences in https://hstspreload.org/. This option
# will add the domain to a hardcoded list that is shipped
# in all major browsers and getting removed from this list
# could take several months.
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;
add_header X-Download-Options noopen;
add_header X-Permitted-Cross-Domain-Policies none;
add_header Referrer-Policy no-referrer;
# Optional: Don't log access to assets
access_log off;
}
location ~ \.(?:png|html|ttf|ico|jpg|jpeg)$ {
try_files $uri /index.php$request_uri;
# Optional: Don't log access to other assets
access_log off;
}
}
EOF
}
install_docker() {
# Check lvm2 , yum-utils , device-mapper-persistent-data package
softwarepackage=("lvm2" "yum-utils" "device-mapper-persistent-data")
for softwarepackagevariable in ${softwarepackage[@]}
do
softwarepackagestate=$(rpm -qa | grep $softwarepackagevariable)
if [ ! -n "$softwarepackagestate" ] ; then
echo "Install $softwarepackagevariable software package"
yum clean all
rm -rf /var/lib/yum/history/*.sqlite
yum install -y $softwarepackagevariable
else
echo "$softwarepackagevariable software packages have been installed."
fi
done
# add docker aliyun repo
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# install docker-ce
yum makecache fast
yum -y install docker-ce
# Start the docker service and configure the boot automatically.
systemctl start docker
systemctl enable docker
# config Docker mirror accelerator and restat service
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"dns": ["114.114.114.114", "114.114.115.115"],
"registry-mirrors": ["https://z001byx4.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload
systemctl restart docker
}
install_nginx() {
# Install nginx repo
echo "Install nginx repo"
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
# Modify nginx repo
nginx_repo
echo "Modify nginx repo"
# Install nginx And openssl component package
yum clean all
rm -rf /var/cache/yum/
rm -rf /var/lib/yum/history/*.sqlite
yum install -y openssl nginx
systemctl start nginx.service
systemctl enable nginx.service
# Optimizing nginx default configuration
sed -i "/^$/{N;/\n$/D}" /etc/nginx/nginx.conf
mv /etc/nginx/conf.d/default.conf /etc/nginx/default.conf
sed -i "/tcp_nopush/a\ \n server_tokens off\;" /etc/nginx/nginx.conf
sed -i "s/worker_processes 1/worker_processes auto/g" /etc/nginx/nginx.conf
sed -i "/worker_processes/a\worker_rlimit_nofile 65535\;" /etc/nginx/nginx.conf
sed -i "s/worker_connections 1024/worker_connections 65535/g" /etc/nginx/nginx.conf
sed -i "/include \/etc\/nginx\/conf.d\/\*.conf/i\ include \/etc\/nginx\/default.conf\;" /etc/nginx/nginx.conf
sed -i "/listen 80\;/a\ listen [::]:80\;" /etc/nginx/default.conf
sed -i "/listen [::]:80\;/a\ listen 443 ssl\;" /etc/nginx/default.conf
sed -i "/listen 443 ssl\;/a\ listen [::]:443 ssl\;" /etc/nginx/default.conf
sed -i "/server_name/a\ \n ssl_certificate \/etc\/nginx\/cert\/root.crt\;" /etc/nginx/default.conf
sed -i "/ssl_certificate/a\ ssl_certificate_key \/etc\/nginx\/cert\/root.key\;" /etc/nginx/default.conf
sed -i "/server_name/a\ \n return 403\;" /etc/nginx/default.conf
# Configure SSL support for nginx
mkdir -p /etc/nginx/cert/
self_certificate ; systemctl restart nginx
# Configuration firewall to open service to nginx
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
}
install_php() {
# Install epel repo
echo "Install epel repo"
rpm -Uvh http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# Modify epel repo
epel_repo
echo "Modify epel repo"
# Install webtatic repo
echo "Install webtatic repo"
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
# Modify webtatic repo
webtatic_repo
echo "Modify webtatic repo"
# Install php and other component package
yum clean all