-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvhost.sh
376 lines (347 loc) · 11.3 KB
/
vhost.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
#!/bin/bash
#
#
# CentOS 7 LLStack
# Author: ivmm <cjwbbs@gmail.com>
# Home: https://www.llstack.com
# Blog: https://www.mf8.biz
#
# * LiteSpeed Enterprise Web Server
# * MySQL 5.5/5.6/5.7/8.0(MariaDB 5.5/10.0/10.1/10.2/10.3)
# * PHP 5.4/5.5/5.6/7.0/7.1/7.2/7.3
# * phpMyAdmin(Adminer)
#
# https://github.com/ivmm/LLStack/
#
# Usage: sh vhost.sh
#
# check root
[ "$(id -g)" != '0' ] && die 'Script must be run as root.'
clear
echo "====================================================================="
echo -e "\033[32mLLStack for CentOS/RedHat 7\033[0m"
echo "====================================================================="
echo -e "\033[32mA tool to auto-compile & install LiteSpeed+MySQL(MariaDB)+PHP on Linux\033[0m"
echo ""
echo -e "\033[32mFor more information please visit https://www.llstack.com/\033[0m"
echo "====================================================================="
#Domain name
domain="mf8.biz"
echo "Please input domain:"
read -p "(Default domain: mf8.biz):" domain
if [ "$domain" = "" ]; then
domain="mf8.biz"
fi
if [ ! -f "//usr/local/lsws/conf/vhosts/$domain.xml" ]; then
echo "==========================="
echo "domain=$domain"
echo "==========================="
else
echo "==========================="
echo "$domain is exist!"
echo "==========================="
exit 0
fi
#WebMaster's Email
webmasteremail="admin@mf8.biz"
echo "Please input The WebMaster's Email:"
read -p "(Example: admin@mf8.biz):" webmasteremail
if [ "$webmasteremail" = "" ]; then
webmasteremail="admin@mf8.biz"
fi
#LSPHP Version
Llsphpversion=$(cat /usr/share/lsphp-default-version)
echo "Please input The PHP Version(If you have installed multiple versions of PHP): "
read -p "PHP Version,Example: lsphp71,lsphp70 or lsphp56: " -r -e -i "${Llsphpversion}" lsphpversion
if [ "$lsphpversion" = "" ]; then
lsphpversion=$(cat /usr/share/lsphp-default-version)
fi
#More domain name
read -p "Do you want to add more domain name? (y/n)" add_more_domainame
if [ "$add_more_domainame" = 'y' ] || [ "$add_more_domainame" = 'Y' ]; then
echo "Please input domain name,example(www.mf8.biz,statics.mf8.biz,imgs.mf8.biz)"
read -p "Please use \",\" between each domain: " moredomain
echo "==========================="
echo domain list="$moredomain"
echo "==========================="
moredomainame=" $moredomain"
fi
#Enable SSL
read -p "Do you want to enable HTTPS? (y/n)" enablessl
if [ "$enablessl" = 'y' ] || [ "$enablessl" = 'Y' ]; then
echo "Please input the Private Key File Path"
read -p "Example:/home/demo/ssl/www.mf8.biz.key " privatekeypath
echo "Please input the Certificate File Path"
read -p "Example:/home/demo/ssl/www.mf8.biz.crt " certificatepath
read -p "Do you want to enable HTTP/3(QUIC)? (y/n) " enablequic
echo "==========================="
echo Private Key File Path="$privatekeypath"
echo Certificate File Path="$certificatepath"
echo "==========================="
chown lsadm:lsadm $privatekeypath
chown lsadm:lsadm $certificatepath
fi
get_char() {
SAVEDSTTY=`stty -g`
stty -echo
stty cbreak
dd if=/dev/tty bs=1 count=1 2> /dev/null
stty -raw
stty echo
stty $SAVEDSTTY
}
echo ""
echo "Press any key to start or CTRL+C to cancel."
char=`get_char`
#Mkdir for vhost
mkdir -p /home/$domain/{public_html,logs,ssl,cgi-bin,cache}
chown -R nobody:nobody /home/$domain/public_html
#add httpd conf Virtual host
cp -f /usr/local/lsws/conf/httpd_config.xml /usr/local/lsws/conf/httpd_config.xml.bak
v1="<virtualHost>"
v2="<name>$domain<\/name>"
v3="<vhRoot>\/home\/$domain<\/vhRoot>"
v4="<configFile>\$SERVER_ROOT\/conf\/vhosts\/$domain.xml<\/configFile>"
v5="<allowSymbolLink>1<\/allowSymbolLink>"
v6="<enableScript>1<\/enableScript>"
v7="<restrained>0<\/restrained>"
v8="<setUIDMode>2<\/setUIDMode>"
v9="<chrootMode>0<\/chrootMode>"
v10="<\/virtualHost>"
vend="<\/virtualHostList>"
sed -i 's/'$vend'/'$v1'\n'$v2'\n'$v3'\n'$v4'\n'$v5'\n'$v6'\n'$v7'\n'$v8'\n'$v9'\n'$v10'\n&/' /usr/local/lsws/conf/httpd_config.xml
if [ "$enablessl" = 'y' ] || [ "$enablessl" = 'Y' ]; then
#add httpd conf listen (https)
l1="<vhostMap>"
l2="<vhost>$domain<\/vhost>"
l3="<domain>$domain,$moredomain<\/domain>"
l4="<\/vhostMap>"
lend="<\/vhostMapList>"
sed -i 's/'$lend'/'$l1'\n'$l2'\n'$l3'\n'$l4'\n&/' /usr/local/lsws/conf/httpd_config.xml
if [ "$add_more_domainame" = 'y' ] || [ "$add_more_domainame" = 'Y' ]; then
l1="<vhostMap>"
l2="<vhost>$domain<\/vhost>"
l3="<domain>$domain,$moredomain<\/domain>"
l4="<\/vhostMap>"
lend="<\/vhostMapList>"
sed -i 's/'$lend'/'$l1'\n'$l2'\n'$l3'\n'$l4'\n&/' /usr/local/lsws/conf/httpd_config.xml
else
l1="<vhostMap>"
l2="<vhost>$domain<\/vhost>"
l3="<domain>$domain<\/domain>"
l4="<\/vhostMap>"
lend="<\/vhostMapList>"
sed -i 's/'$lend'/'$l1'\n'$l2'\n'$l3'\n'$l4'\n&/' /usr/local/lsws/conf/httpd_config.xml
fi
#add vhost conf (https)
cat >>/usr/local/lsws/conf/vhosts/$domain.xml<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<virtualHostConfig>
<docRoot>/home/$domain/public_html</docRoot>
<adminEmails>$webmasteremail</adminEmails>
<enableGzip>1</enableGzip>
<logging>
<log>
<useServer>1</useServer>
<fileName>/home/$domain/logs/$domain_errors.log</fileName>
<logLevel>ERROR</logLevel>
<rollingSize>100M</rollingSize>
</log>
<accessLog>
<useServer>0</useServer>
<fileName>/home/$domain/logs/$domain.access.log</fileName>
<logHeaders>3</logHeaders>
<rollingSize>100M</rollingSize>
<keepDays>30</keepDays>
<compressArchive>1</compressArchive>
</accessLog>
</logging>
<index>
<useServer>0</useServer>
<indexFiles>index.html, index.htm, index.php</indexFiles>
</index>
<scriptHandlerList>
<scriptHandler>
<suffix>php</suffix>
<type>lsapi</type>
<handler>$lsphpversion</handler>
</scriptHandler>
</scriptHandlerList>
<expires>
<enableExpires>1</enableExpires>
</expires>
<cache>
<storage>
<cacheStorePath>/home/$domain/cache</cacheStorePath>
<litemage>0</litemage>
</storage>
</cache>
<extProcessorList>
<extProcessor>
<type>lsapi</type>
<name>$lsphpversion</name>
<address>uds://tmp/lshttpd/$domain-$lsphpversion.sock</address>
<maxConns>35</maxConns>
<env>PHP_LSAPI_MAX_REQUESTS=5000</env>
<env>PHP_LSAPI_CHILDREN=35</env>
<initTimeout>180</initTimeout>
<retryTimeout>0</retryTimeout>
<persistConn>1</persistConn>
<pcKeepAliveTimeout>30</pcKeepAliveTimeout>
<respBuffer>0</respBuffer>
<autoStart>1</autoStart>
<path>/usr/bin/$lsphpversion</path>
<backlog>100</backlog>
<instances>1</instances>
<extMaxIdleTime>10</extMaxIdleTime>
<priority>0</priority>
<memSoftLimit>1024M</memSoftLimit>
<memHardLimit>1024M</memHardLimit>
<procSoftLimit>400</procSoftLimit>
<procHardLimit>500</procHardLimit>
</extProcessor>
</extProcessorList>
<contextList>
<context>
<type>cgi</type>
<uri>/cgi-bin/</uri>
<location>/home/$domain/cgi-bin/</location>
<accessControl>
</accessControl>
<rewrite>
</rewrite>
<cachePolicy>
</cachePolicy>
<addDefaultCharset>off</addDefaultCharset>
</context>
</contextList>
<vhssl>
<keyFile>$privatekeypath</keyFile>
<certFile>$certificatepath</certFile>
<certChain>1</certChain>
<renegProtection>1</renegProtection>
<sslSessionCache>1</sslSessionCache>
<sslSessionTickets>1</sslSessionTickets>
<enableSpdy>4</enableSpdy>
<enableQuic>0</enableQuic>
</vhssl>
</virtualHostConfig>
EOF
if [ "$enablequic" = 'y' ] || [ "$enablequic" = 'Y' ]; then
sed -i "s@<enableQuic>0</enableQuic>@<enableQuic>1</enableQuic>@g" /usr/local/lsws/conf/vhosts/$domain.xml
fi
else
#add httpd conf listen(http)
l1="<vhostMap>"
l2="<vhost>$domain<\/vhost>"
l3="<domain>$domain,$moredomain<\/domain>"
l4="<\/vhostMap>"
lend="<\/vhostMapList><!--HTTP-->"
sed -i 's/'$lend'/'$l1'\n'$l2'\n'$l3'\n'$l4'\n&/' /usr/local/lsws/conf/httpd_config.xml
if [ "$add_more_domainame" = 'y' ] || [ "$add_more_domainame" = 'Y' ]; then
l1="<vhostMap>"
l2="<vhost>$domain<\/vhost>"
l3="<domain>$domain,$moredomain<\/domain>"
l4="<\/vhostMap>"
lend="<\/vhostMapList><!--HTTP-->"
sed -i 's/'$lend'/'$l1'\n'$l2'\n'$l3'\n'$l4'\n&/' /usr/local/lsws/conf/httpd_config.xml
else
l1="<vhostMap>"
l2="<vhost>$domain<\/vhost>"
l3="<domain>$domain<\/domain>"
l4="<\/vhostMap>"
lend="<\/vhostMapList><!--HTTP-->"
sed -i 's/'$lend'/'$l1'\n'$l2'\n'$l3'\n'$l4'\n&/' /usr/local/lsws/conf/httpd_config.xml
fi
#add vhost conf (http)
cat >>/usr/local/lsws/conf/vhosts/$domain.xml<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<virtualHostConfig>
<docRoot>/home/$domain/public_html</docRoot>
<adminEmails>$webmasteremail</adminEmails>
<enableGzip>1</enableGzip>
<logging>
<log>
<useServer>1</useServer>
<fileName>/home/$domain/logs/$domain_errors.log</fileName>
<logLevel>ERROR</logLevel>
<rollingSize>100M</rollingSize>
</log>
<accessLog>
<useServer>0</useServer>
<fileName>/home/$domain/logs/$domain.access.log</fileName>
<logHeaders>3</logHeaders>
<rollingSize>100M</rollingSize>
<keepDays>30</keepDays>
<compressArchive>1</compressArchive>
</accessLog>
</logging>
<index>
<useServer>0</useServer>
<indexFiles>index.html, index.htm, index.php</indexFiles>
</index>
<scriptHandlerList>
<scriptHandler>
<suffix>php</suffix>
<type>lsapi</type>
<handler>$lsphpversion</handler>
</scriptHandler>
</scriptHandlerList>
<expires>
<enableExpires>1</enableExpires>
</expires>
<cache>
<storage>
<cacheStorePath>/home/$domain/cache</cacheStorePath>
<litemage>0</litemage>
</storage>
</cache>
<extProcessorList>
<extProcessor>
<type>lsapi</type>
<name>$lsphpversion</name>
<address>uds://tmp/lshttpd/$domain-$lsphpversion.sock</address>
<maxConns>35</maxConns>
<env>PHP_LSAPI_MAX_REQUESTS=5000</env>
<env>PHP_LSAPI_CHILDREN=35</env>
<initTimeout>180</initTimeout>
<retryTimeout>0</retryTimeout>
<persistConn>1</persistConn>
<pcKeepAliveTimeout>30</pcKeepAliveTimeout>
<respBuffer>0</respBuffer>
<autoStart>1</autoStart>
<path>/usr/bin/$lsphpversion</path>
<backlog>100</backlog>
<instances>1</instances>
<extMaxIdleTime>10</extMaxIdleTime>
<priority>0</priority>
<memSoftLimit>1024M</memSoftLimit>
<memHardLimit>1024M</memHardLimit>
<procSoftLimit>400</procSoftLimit>
<procHardLimit>500</procHardLimit>
</extProcessor>
</extProcessorList>
<contextList>
<context>
<type>cgi</type>
<uri>/cgi-bin/</uri>
<location>/home/$domain/cgi-bin/</location>
<accessControl>
</accessControl>
<rewrite>
</rewrite>
<cachePolicy>
</cachePolicy>
<addDefaultCharset>off</addDefaultCharset>
</context>
</contextList>
</virtualHostConfig>
EOF
fi
chown -R lsadm:lsadm /usr/local/lsws/conf/vhosts/$domain.xml
service lsws restart
echo "========================================================================="
echo "The Virtual host has been created"
echo "The path of the Virtual host is /home/$domain/"
echo "Please upload the web files into /home/$domain/public_html"
echo "========================================================================="