-
Notifications
You must be signed in to change notification settings - Fork 0
executable file
·33 lines (21 loc) · 1.16 KB
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
#!/usr/bin/env bash
# Customizing a 404-error_page
# Updating Packages before performing installations
sudo apt-get update
sudo apt-get -y install nginx
HOST_NAME=$(hostname)
# Creating an index.html page
echo "Hello World!" | sudo tee /var/www/html/index.html
# Performing a "moved permanently redirection" (301)
string_for_replacement="server_name _;\n\trewrite ^\/redirect_me https:\/\/github.com\/Unique-Usman permanent;"
sudo sed -i "s/server_name _;/$string_for_replacement/" /etc/nginx/sites-available/default
# Creating a 404 Custom error page
echo "Ceci n'est pas une page" | sudo tee /var/www/html/404.html
new_string="listen 80 default_server;\n\terror_page 404 \/404.html;\n\tlocation = \/404.html {\n\t\troot \/var\/www\/html;\n\t\tinternal;\n\t}"
sudo sed -i "s/listen 80 default_server;/$new_string/" /etc/nginx/sites-available/default
string_for_replacement="try_files $uri $uri/ =404;\n\tadd_header X-Served-By '$HOST_NAME';"
sudo sed -i "s/try_files $uri $uri/ =404;/$string_for_replacement/" /etc/nginx/sites-available/default
# Testing configurations for syntax errors
sudo nginx -t
# restart nginx after implementing changes
sudo service nginx restart