-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsite-config
executable file
·72 lines (53 loc) · 1.72 KB
/
site-config
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
#!/bin/bash
#
# usage: sudo ./site-config www.domain.test
# Creates the folder to put your site in, creates a nginx config,
# links it, and restarts nginx
#
# - Your websites are stored in /var/www/ and each contain a public/ folder
echo -e "Setting up $1 in nginx"
DIRECTORY="/var/www/$1/web"
if [ -d $DIRECTORY ]; then
echo -e "The $1 folder already exists."
else
mkdir -p $DIRECTORY
echo -e "Making the $1 folder"
echo -e "Making a test index.php"
echo "$1 is currently under maintenance" > "$DIRECTORY/index.php"
fi
if [ -f /etc/nginx/sites-available/$1 ]; then
echo -e "Removing the old config file for $1."
rm /etc/nginx/sites-available/$1
fi
echo -e "Creating the sites-available file for $1."
sudo cat <<'EOF' >> /etc/nginx/sites-available/$1
server {
listen 80;
listen [::]:80;
server_name SITE;
root /var/www/SITE/web;
index index.php index.html index.htm index.nginx-debian.html;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
EOF
sudo sed -i "s/SITE/$1/g" "/etc/nginx/sites-available/$1"
if [ -f /etc/nginx/sites-enabled/$1 ]; then
echo -e "Removing the old sites-enabled file link for $1."
rm /etc/nginx/sites-enabled/$1
fi
echo -e "Linking $1 in sites-enabled."
cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/$1
echo -e "Restarting Nginx"
service nginx restart