-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx:host.sh
67 lines (59 loc) · 1.66 KB
/
nginx:host.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
#!/bin/bash
echo "Enter Project path E.g /var/www/MYPROJECT"
read path
if [[ -d "$path" ]]; then
echo "Enter App Name E.g(NewsApp) without space"
read name
echo "Enter domain names E.g google.com"
read domain
echo "Would you like to generate an nginx VHost?
Y|n"
read s
if [[ "$s" == "y" || "$s" == "yes" ]]; then
sudo echo "server{
root $path;
index index.php index.html index.htm index.nginx-debian.html;
server_name $domain;
add_header X-XSS-Protection \"1; mode=block\" always;
add_header X-Content-Type-Options nosniff always;
add_header X-Frame-Options \"DENY\" always;
add_header Referrer-Policy no-referrer-when-downgrade always;
server_tokens off;
charset utf-8;
location = /favicon.ico {
access_log off; log_not_found off;
}
location / {
try_files \$uri \$uri/ /index.php\$is_args\$args;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
location = /xmlrpc.php {
deny all;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
" >"/etc/nginx/sites-available/$name"
sudo ln -s /etc/nginx/sites-available/"$name" /etc/nginx/sites-enabled/
sudo nginx -t
echo "Would you like to restart nginx server?
Y|n"
read r
if [[ "$r" == "y" || "$r" == "yes" ]]; then
sudo service nginx restart
fi
echo "$name added to sites"
fi
else
echo "Error: Directory $path does not exists."
fi