forked from necenzurat/webservertools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.sh
executable file
·114 lines (96 loc) · 2.36 KB
/
server.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
#!/bin/bash
function check_root() {
if [ $(id -u) -ne 0 ]
then
echo "Y U NO root???" 2>&1
exit 1
fi
}
check_root
function do_new_host() {
read -p "Enter the name of the server (example.com)? " servername
echo "generating config file for" $servername;
echo "Generated file /etc/nginx/conf.d/$servername.conf"
cat > /etc/nginx/conf.d/$servername.conf <<END
server {
# listen for ipv4, Todo: ipv6?
listen 80;
server_name $servername www.$servername;
access_log /home/$servername/logs/access.log;
error_log /home/$servername/logs/error.log;
root /home/$servername/public;
server_tokens off;
add_header Served-From \$server_addr;
# Disable .htaccess and other hidden files
location /. {
return 404;
}
# uncomment this for index.php to be the router
try_files \$uri \$uri/ /index.php?q=\$uri&\$args;
default_type text/html;
index index.html index.php;
# the php part
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO \$fastcgi_path_info;
fastcgi_param PATH_TRANSLATED \$document_root\$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
}
# no favicon.ico in logs
location = /favicon.ico {
log_not_found off;
access_log off;
}
# no robots.txt in logs
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
}
END
cat > /etc/logrotate.d/$servername <<END
/home/$servername/logs/*.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 640 nginx adm
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
endscript
}
END
# make home dir folder
mkdir /home/$servername
echo "Generated /home/$servername";
# make logs folder
mkdir /home/$servername/logs
echo "Generated /home/$servername/logs";
# make public folder
mkdir /home/$servername/public
echo "Generated /home/$servername/public";
# i can haz permissions for www-data?
chown -R www-data:www-data /home/$servername
# yes, yes you can
# make demo...
cat > /home/$servername/public/index.php <<END
<?php echo "hello world from $servername";
END
# reboot nginx
service nginx restart
}
# loop it
while true; do
read -p "Do you wish add a new host? " yn
case $yn in
[Yy]* ) do_new_host; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done