-
Notifications
You must be signed in to change notification settings - Fork 0
/
0-custom_http_response_header
executable file
·74 lines (61 loc) · 1.81 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
#!/usr/bin/env bash
# Setup web-02 similarly to web-01
echo -e "Updating and perfoming minor check...\n"
function install() {
command -v "$!" &> /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 "\nPerforming checks...\n"
# Allow Nginx on firewall
sudo ufw allow 'Nginx HTTP'
# Transfer 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 new index
echo "Hello World!" > /var/www/html/index.html
# Create new error page
echo "Ceci n'est pas une page" > /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://femiajanaku.vercel.app 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