-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-symfony-old-nginx-vhost
118 lines (98 loc) · 2.86 KB
/
create-symfony-old-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
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
#!/usr/bin/env php
<?php
if (!isset($argv[1])) {
echo "You need to set domain name, for example: create-symfony-old-vhost mysite.ru\n\n";
echo "Or with specific directory in /var/www/: create-symfony-old-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.'/web;
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 all . files
location ~ /\.(ht|git) {
deny all;
}
location / {
# try to serve file directly, fallback to app.php
try_files $uri /app.php$is_args$args;
}
location @rewriteapp {
rewrite ^(.*)$ /app.php/$1 last;
}
location ~ ^/app\.php(/|$) {
include php_default;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
# Prevents URIs that include the front controller. This will 404:
# http://domain.tld/app.php/some-path
# Remove the internal directive to allow URIs like this
internal;
}
# Accelerator cache cleaner
location ~ /apc(.+)\.php(/|$) {
include php_default;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
# Statics
location ~ ^/bundles {
access_log off;
expires 30d;
# Font files
#if ($filename ~* ^.*?\.(eot)|(ttf)|(woff)$){
# add_header Access-Control-Allow-Origin *;
#}
try_files $uri @rewriteapp;
}
location ~ ^/_media {
access_log off;
expires 30d;
try_files $uri @rewriteapp;
}
location ~ ^/media {
access_log off;
expires 30d;
try_files $uri @rewriteapp;
}
}
';
$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}/web");
file_put_contents("/var/www/{$dir}/web/app.php", $domain . ' is under construction...');
file_put_contents("/var/www/{$dir}/web/robots.txt", $robotsTxt);
system("chown -hR www-data:www-data /var/www/{$dir}/web");
system('/etc/init.d/nginx reload');