环境:ubuntu-14.04.3(预装python3.4)
1.flask(Web框架)
2.gunicorn(python Wsgi http server)
1.安装
sudo pip3 install gunicorn 复制代码
2.修改入口文件
from werkzeug.contrib.fixers import ProxyFix app.wsgi_app = ProxyFix(app.wsgi_app) app.run() 复制代码
3.启动
gunicorn -w 4 -b 127.0.0.1:8000 入口文件名:应用实例 复制代码
3.upstart(服务进程管理)
myapp.conf (开机启动) ''' description "flask app" start on runlevel [2345] stop on runlevel [!2345] respawn setuid root setgid www-data chdir /home/zhangxin/PycharmProjects/flaskApp # 指令被执行的目录 exec gunicorn -b 0.0.0.0:8000 app:app ''' 1.目录: cd /etc/init 2.启动:sudo start myapp 3.状态:sudo status myapp 4.停止:sudo stop myapp 5.重启:sudo restart myapp 复制代码
4.nginx(代理服务)
1.安装
sudo apt-get install nginx /etc/nginx/sites-available sudo nano default ''' server { listen 8899; server_name 127.0.0.1; location / { proxy_pass http://127.0.0.1:8000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } ''' 复制代码
2.重启
sudo service nginx restart 复制代码
5.修改pip镜像地址:
/home/<username>/.pip/pip.conf [global] index-url = http://mirrors.aliyun.com/pypi/simple/ 复制代码
6.安装 pip3
sudo apt-get install python3-pip 复制代码
7.pipreqs
1.安装
sudo pip3 install pipreqs 复制代码
2.生成
pip3 freeze > requirements.txt 复制代码
3.执行
sudo pip3 install -r requirements.txt