1
+ #! /bin/bash
2
+
3
+
4
+ printf " =========================================================================\n"
5
+ printf " Add New A Domain\n"
6
+ printf " =========================================================================\n"
7
+ echo -n " Type the user contain list domain or leave null for set /home folder and press [ENTER]: "
8
+ read user
9
+ echo -n " Type the domain name and press [ENTER]: "
10
+ read domain
11
+ if [ " $domain " = " " ]; then
12
+ echo " Incorrect, please try again"
13
+ exit
14
+ fi
15
+ if [ " $user " = " " ]; then
16
+ domain_path=" $domain "
17
+ else
18
+ domain_path=" $user /$domain "
19
+ fi
20
+
21
+ if [ -f /etc/nginx/sites-enabled/$domain .conf ]; then
22
+ echo " $domain already exist"
23
+ echo " Bye...!"
24
+ exit
25
+ fi
26
+ mkdir -p " /home/$domain_path /public_html"
27
+ mkdir -p " /home/$domain_path /logs"
28
+
29
+ cp -p /etc/tdc/action/index.html /home/$domain /public_html/index.html
30
+
31
+ chown www-data:www-data /home/$domain_path
32
+ chown -R www-data:www-data /home/* /public_html
33
+ chown -R www-data:www-data /var/lib/php
34
+
35
+ domain_alias=" www.$domain "
36
+ if [[ $domain == * www* ]]; then
37
+ domain_alias=${domain/ www./ ' ' }
38
+ fi
39
+
40
+ cat > " /etc/nginx/sites-enabled/$domain .conf" << END
41
+ server {
42
+ listen 80;
43
+
44
+ server_name $domain_alias ;
45
+ rewrite ^(.*) http://$domain \$ 1 permanent;
46
+ }
47
+
48
+ server {
49
+ listen 80;
50
+
51
+ # access_log off;
52
+ access_log /home/$domain_path /logs/access.log;
53
+ # error_log off;
54
+ error_log /home/$domain_path /logs/error.log;
55
+
56
+ root /home/$domain_path /public_html;
57
+ index index.php index.html index.htm;
58
+ server_name $domain ;
59
+
60
+ location / {
61
+ try_files \$ uri \$ uri/ /index.php?\$ args;
62
+ }
63
+
64
+ # Custom configuration
65
+ include /home/$domain_path /public_html/*.conf;
66
+
67
+ location ~ \.php$ {
68
+ fastcgi_split_path_info ^(.+\.php)(/.+)$;
69
+ include /etc/nginx/fastcgi_params;
70
+ fastcgi_pass unix:/run/php/php7.0-fpm.sock;
71
+ fastcgi_index index.php;
72
+ fastcgi_connect_timeout 300;
73
+ fastcgi_send_timeout 300;
74
+ fastcgi_read_timeout 300;
75
+ fastcgi_buffer_size 32k;
76
+ fastcgi_buffers 8 16k;
77
+ fastcgi_busy_buffers_size 32k;
78
+ fastcgi_temp_file_write_size 32k;
79
+ fastcgi_intercept_errors on;
80
+ fastcgi_param SCRIPT_FILENAME /home/$domain_path /public_html\$ fastcgi_script_name;
81
+ }
82
+
83
+ location ~ /\. {
84
+ deny all;
85
+ }
86
+
87
+ location = /favicon.ico {
88
+ log_not_found off;
89
+ access_log off;
90
+ }
91
+
92
+ location = /robots.txt {
93
+ allow all;
94
+ log_not_found off;
95
+ access_log off;
96
+ }
97
+
98
+ location ~* \.(3gp|gif|jpg|jpeg|png|ico|wmv|avi|asf|asx|mpg|mpeg|mp4|pls|mp3|mid|wav|swf|flv|exe|zip|tar|rar|gz|tgz|bz2|uha|7z|doc|docx|xls|xlsx|pdf|iso|eot|svg|ttf|woff)$ {
99
+ gzip_static off;
100
+ add_header Pragma public;
101
+ add_header Cache-Control "public, must-revalidate, proxy-revalidate";
102
+ access_log off;
103
+ expires 30d;
104
+ break;
105
+ }
106
+
107
+ location ~* \.(txt|js|css)$ {
108
+ add_header Pragma public;
109
+ add_header Cache-Control "public, must-revalidate, proxy-revalidate";
110
+ access_log off;
111
+ expires 30d;
112
+ break;
113
+ }
114
+ }
115
+ END
116
+ service nginx reload
117
+
118
+ echo " Created successfully $domain "
119
+ echo " Upload code to /home/$domain_path /public_html/"
120
+ echo " Log of $domain show in /home/$domain_path /logs"
0 commit comments