flask 部署
gunicorn
1. 安装gunicorn:
pip install gunicorn
2. 配置gunicorn:
创建 wgis.py 文件
# coding: utf-8
from app import app #导入自己的应用
application = app()
3. 启动gunicron:
gunicorn -w 4 -b 127.0.0.1:9080 wsgi:application
#-w 是开几个线程; wsig 文件名, applicantion是应用名字;
或者:
gunicorn -b 127.0.0.1:9080 wsgi:application
nginx
1. 安装nginx:
-
首先安装依赖包(centos):
yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel
-
再者从官网下载:
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
解压:
tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1
-
配置:
./configure
如果出现:error: the HTTP gzip module requires the zlib library.
需要安装:yum install -y zlib-devel pcre openssl
由于之前已经安装,所以很少出现这个问题; -
编译:
./configure && make && make install
-
安装位置:
/usr/local/nginx
-
配置文件位置:
/usr/local/nginx/conf
2. 启动:
./usr/local/nginx/sbin/nginx
//启动
./usr/local/nginx/sbin/nginx -s stop
//停止
./usr/local/nginx/sbin/nginx -s reload
//重启
配置nginx和gunicron:
server {
listen 80;
server_name example.org; # 这是HOST机器的外部域名,用地址也行
location / {
proxy_pass http://127.0.0.1:9080; # 这里是指向 gunicorn host 的服务地址
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
最后:
启动nginx和gunicorn
gunicorn -b 127.0.0.1:9080 wsgi:application
./usr/local/nginx/sbin/nginx
在浏览器输入localhost:80 大功告成。