-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-nginx-vhost
executable file
·75 lines (60 loc) · 1.7 KB
/
create-nginx-vhost
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
#!/usr/bin/env php
<?php
if (!isset($argv[1])) {
echo "You need to set domain name, for example: create-nginx-vhost mysite.ru\n";
echo "Or with specific directory in /var/www/: create-nginx-vhost mysite.ru my_site_dir\n";
exit(1);
}
$domain = $argv[1];
if (isset($argv[2]) and !empty($argv[2])) {
$dir = $argv[2];
} else {
$dir = $domain;
}
if (file_exists('/var/www/' . $dir)) {
echo "Domain $domain in $dir is exists.\n";
exit(1);
}
$conf = '
server {
server_name '.$domain.';
root /var/www/'.$dir.'/public;
error_log /var/log/nginx/'.$dir.'_errors.log;
access_log /var/log/nginx/'.$dir.'_access.log;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Deny dot files
location ~ /\.(ht|git) {
deny all;
}
index index.php;
location ~ \.php$ {
try_files $uri = 404;
include php_default;
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
';
$robotsTxt = "
# www.robotstxt.org/
# www.google.com/support/webmasters/bin/answer.py?hl=en&answer=156449
User-Agent: *
Disallow: /cgi-bin/
Disallow: /admin/
";
file_put_contents('/etc/nginx/sites-enabled/'.$dir.'.conf', $conf);
mkdir("/var/www/{$dir}");
mkdir("/var/www/{$dir}/public");
file_put_contents("/var/www/{$dir}/public/index.php", $domain . ' is under construction...');
file_put_contents("/var/www/{$dir}/public/robots.txt", $robotsTxt);
system("chown -hR www-data:www-data /var/www/{$dir}/public");
system('/etc/init.d/nginx reload');