flask,gunicorn,supervisor,nginx配
1,申请阿里云主机
2,apt-get update
3,apt-get install pip
4,pip install virtualenv
5,virtualenv venv
6,source venv/bin/activate
7,pip install flask
8,vim myapp.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'hello world !'
if __name__ == '__main__':
app.debug =True
app.run()
9,apt-get install nginx
查询nginx错误:nginx -t -c /etc/nginx/nginx.conf
10,修改nginx配置
vim /etc/nginx/sites-available/default
vim /etc/nginx/sites-enabled/default
server {
listen 80;
server_name xxxxxxxx;
client_max_body_size 10M;
location / {
proxy_pass http://0.0.0.0:8000;
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;
}
}
service nginx start
service nginx restart
11,安装supervisor
pip install supervisor
12,配置supervisor
echo_supervisord_conf > supervisor.conf
[program:myapp]
command=/root/venv/bin/gunicorn -w 4 -b 0.0.0.0:8000 myapp:app
directory=/root
startsecs=0
stopwaitsecs=0
autostart=true
autorestart=true
stdout_logfile=/root/log/gunicorn.log
stderr_logfile=/root/log/gunicorn.err
13,启动supervisor
supervisord -c supervisor.conf
supervisorctl -c supervisor.conf start all
14,配置阿里云网络安全
15,使用阿里云服务器公网ip访问