forked from flawcode/flawcode-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.txt
105 lines (69 loc) · 3.08 KB
/
build.txt
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
documentation on how to deploy:
install the dependencies
sudo apt-get update
sudo apt-get install python3-pip python3-dev nginx
create the folder
mkdir flawcode.com
cd flawcode.com
mkdir logs
create the virtualenv
sudo apt-get install python3-venv
python3.5 -m venv venv
source venv/bin/activate
pip install flask gunicorn
the app
from flask import Flask
from werkzeug.contrib.fixers import ProxyFix
app = Flask(__name__)
@app.route('/')
def hello():
return "Hello world!"
app.wsgi_app = ProxyFix(app.wsgi_app)
if __name__ == '__main__':
app.run()
run the gunicorn command
(venv) joy@flawcode:~/flawcode.com$ gunicorn --bind 0.0.0.0:5000 hello:app
[2017-04-17 07:47:46 +0000] [17832] [INFO] Starting gunicorn 19.7.1
[2017-04-17 07:47:46 +0000] [17832] [INFO] Listening at: http://0.0.0.0:5000 (17832)
[2017-04-17 07:47:46 +0000] [17832] [INFO] Using worker: sync
[2017-04-17 07:47:46 +0000] [17835] [INFO] Booting worker with pid: 17835
create sites available flawcode
joy@flawcode:~/flawcode.com$ sudo cat /etc/nginx/sites-available/flawcode.com
server {
listen 80;
server_name 127.0.0.1;
root /home/joy/flawcode.com/;
access_log /home/joy/flawcode.com/logs/access.log;
error_log /home/joy/flawcode.com/logs/error.log;
location / {
proxy_pass http://127.0.0.1:5000/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
create the link to sites enabled and delete the default
sudo rm -v /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/flawcode.com /etc/nginx/sites-enabled/
supervisor
(venv) joy@flawcode:~/flawcode.com$ cat /etc/supervisor/conf.d/flawcode.conf
[program:flawcode]
command = /home/joy/flawcode.com/venv/bin/python /home/joy/flawcode.com/venv/bin/gunicorn -w 4 --bind 0.0.0.0:5000 hello:app
directory = /home/joy/flawcode.com
user = joy
stdout_logfile = /home/joy/flawcode.com/logs/gunicorn_stdout.log
stderr_logfile = /home/joy/flawcode.com/logs/gunicorn_stderr.log
redirect_stderr = True
environment = PRODUCTION=1
to restart supervisor
sudo supervisorctl restart flawcode
So once you are done with changing the code and deploying to production git pull from upstream and then restart the supervisor
Next to change the firewall rules
references:
http://www.onurguzel.com/how-to-run-flask-applications-with-nginx-using-gunicorn/
https://realpython.com/blog/python/kickstarting-flask-on-ubuntu-setup-and-deployment/
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04
http://alexandersimoes.com/hints/2015/10/28/deploying-flask-with-nginx-gunicorn-supervisor-virtualenv-on-ubuntu.html
http://flask.pocoo.org/docs/0.12/deploying/wsgi-standalone/