-
Notifications
You must be signed in to change notification settings - Fork 0
/
configs_nginx
53 lines (39 loc) · 1.6 KB
/
configs_nginx
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
#!/usr/bin/env bash
# Nginx Configs
echo -e "\t>>> Updating sys, installing Nginx and starting it...\n"
sudo apt-get -y update
sudo apt-get -y install nginx
sudo service nginx start
# By default FireWall blocks the incoming traffic over HTTP
# on Nginx for security reasons, so we need to allowing this
echo -e "\n\t>>> Make FireWall to allow incoming traffic through HTTP...\n"
sudo ufw allow "Nginx HTTP"
echo -e "\n\t>>> Backing up files & Setting up configurations...\n"
# Give ownership to the user for easy accessing and editing and backing up
sudo chown -R "$USER":"$USER" /var/www/html
sudo chmod -R 755 /var/www/html
cp /var/www/html/index.nginx-debian.html /var/www/html/index.nginx-debian.html.backup
sudo chown -R "$USER":"$USER" /etc/nginx
sudo chmod -R 755 /etc/nginx
cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.backup
# Task 1: Hello World
echo "Hello World!" | sudo tee /var/www/html/index.nginx-debian.html
# Task 3 - 4: Redirecting, Error_404
echo "Ceci n'est pas une page" | sudo tee /var/www/html/error_404.html
sudo tee /etc/nginx/sites-available/default > /dev/null << 'EOF'
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html index.htm index.nginx-debian.html;
server_name _;
rewrite ^/redirect_me https://www.youtube.com/watch?v=QH2-TGUlwu4 permanent;
error_page 404 /error_404.html;
add_header X-Served-By $hostname;
location / {
try_files $uri $uri/ =404;
}
}
EOF
sudo service nginx restart
echo -e "\n\t>>> Completed.\n"