-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp-server-config
82 lines (73 loc) · 2.25 KB
/
app-server-config
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
echo "Updating Packages and Installing Requirements"
# Update Package Manager
sudo apt-get update
sudo apt-get install -y nginx
# Install pip
sudo apt-get install -y python3-pip
# Install Flask, flask_cors, sqlalchemy Using PIP
pip install flask
pip install flask_cors
pip install sqlalchemy
# Install net-tools
sudo apt install -y net-tools
# Install GUNICORN
sudo apt-get install -y gunicorn
# Remove any current AIRBNB Repositoty
rm -rf AirBnB_clone_v*
# Clone My Repository
git clone https://github.com/victorpreston/AirBnB_clone_v2
git clone https://github.com/victorpreston/AirBnB_clone_v3
git clone https://github.com/victorpreston/AirBnB_clone_v4
# Change Directory
cd AirBnB_clone_v2
# Switch Branches
git checkout app-server
# Define the path to the Nginx configuration file to be overwritten
NGINX_CONFIG="/etc/nginx/sites-enabled/default"
# Overwrite the Nginx configuration file with the provided configuration
sudo tee "$NGINX_CONFIG" > /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 _;
add_header X-Served-By \$hostname;
location /hbnb_static {
alias /data/web_static/current/;
}
location /static/ {
alias /home/ubuntu/AirBnB_clone_v4/web_dynamic/static/;
try_files \$uri \$uri/ =404;
}
location / {
proxy_pass http://0.0.0.0:5003;
}
location /airbnb-onepage {
proxy_pass http://0.0.0.0:5000/airbnb-onepage;
}
location ~ ^/airbnb-dynamic/number_odd_or_even/([0-9]+)$ {
proxy_pass http://0.0.0.0:5001/number_odd_or_even/\$1;
}
location /api/ {
proxy_pass http://0.0.0.0:5002;
}
if (\$request_filename ~ redirect_me){
rewrite ^ https://th3-gr00t.tk/ permanent;
}
error_page 404 /error_404.html;
location = /error_404.html {
internal;
}
}
EOF
# Restart Nginx to apply the changes
sudo systemctl restart nginx
echo "Nginx configuration has been successfully updated."
# Setup tmux session for task 4
cd /home/ubuntu/AirBnB_clone_v3
tmux new-session -d 'gunicorn --bind 0.0.0.0:5002 api.v1.app:app'
# Setup tmux session for task 5
cd /home/ubuntu/AirBnB_clone_v4
git checkout app-server
echo "Done !!!!"