-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy-rest-ml.sh
More file actions
executable file
·48 lines (42 loc) · 1.82 KB
/
Copy pathdeploy-rest-ml.sh
File metadata and controls
executable file
·48 lines (42 loc) · 1.82 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /bin/bash
# Install and configure nginx
function setup_nginx() {
printf "***************************************************\n\t\tSetting up nginx \n***************************************************\n"
echo ======= Installing nginx =======
apt-get install -y nginx
# Configure nginx routing
echo ======= Configuring nginx =======
echo ======= Removing default config =======
rm -rf /etc/nginx/sites-available/default
rm -rf /etc/nginx/sites-enabled/default
echo ======= Replace config file =======
bash -c 'cat <<EOF > /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
location / {
# reverse proxy and serve the app
# running on the localhost:8000
proxy_pass http://127.0.0.1:8000/;
proxy_set_header HOST \$host;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOF'
echo ======= Create a symbolic link of the file to sites-enabled =======
ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/
nginx -t
}
#Serve the web app through gunicorn
function launch_app() {
printf "***************************************************\n\t\tServing the App \n***************************************************\n"
gunicorn app:app --timeout 300 --bind 0.0.0.0:8000
}
######################################################################
######################## RUNTIME ##########################
######################################################################
setup_nginx
launch_app