-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path0-custom_http_response_header
executable file
·84 lines (69 loc) · 1.92 KB
/
0-custom_http_response_header
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
#!/usr/bin/env bash
# duplicate web-01 to web-02
# these scripts are an upgrade from the web-server scripts...
# uncomment to see the script run in action
#set -x
echo -e "Updating and doing some minor checks...\n"
function install() {
command -v "$1" &> /dev/null
#shellcheck disable=SC2181
if [ $? -ne 0 ]; then
echo -e " Installing: $1$\n"
sudo apt-get update -y -qq && \
sudo apt-get install -y "$1" -qq
echo -e "\n"
else
echo -e " ${1} is already installed.\n"
fi
}
install nginx #install nginx
echo -e "\nSetting up some minor stuff.\n"
# allowing nginx on firewall
sudo ufw allow 'Nginx HTTP'
# Give the user ownership to website files for easy editing
if [ -d "/var/www" ]; then
sudo chown -R "$USER":"$USER" /var/www
sudo chmod -R 755 /var/www
else
sudo mkdir -p /var/www
sudo chown -R "$USER":"$USER" /var/www
sudo chmod -R 755 /var/www
fi
# create directories if not present
for dir in /var/www/{html,error}; do
if ! [ -d "$dir" ]; then
mkdir -p "$dir"
fi
done
# creating new index
echo "Hello World!" > /var/www/html/index.html
# create new error page
echo "Hey there, you seem to be missing.\n There is nothing here." > /var/www/html/error_404.html
# backup default server config file
sudo cp /etc/nginx/sites-enabled/default nginx-sites-enabled_default.backup
server_config=\
"server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html
server_name_;
add_header X-Served-By \$hostname;
location / {
try_files \$uri \$uri/ =404;
}
if (\$request_filename ~ redirect_me){
rewrite ^ https://th3-gr00t.tk/ permanent;
}
error_page 404 /error_404.html;
location = /error_404.html {
internal;
}
}"
#shellcheck disable=SC2154
echo "$server_config" | sudo dd status=none of=/etc/nginx/sites-enabled/default
if [ "$(pgrep -c nginx)" -le 0 ]; then
sudo service nginx start
else
sudo service nginx restart
fi