centos部署flask

1.先安裝uwsgi pip install uwsgipython

2.在你的項目根目錄下建立一個配置文件uwsgiconfig.ini(uwsgi支持多種配置文件格式,xml,ini,json等)nginx

[uwsgi]socket = 127.0.0.1:8001 //啓動程序時所使用的地址和端口,一般在本地運行flask項目,web

//地址和端口是127.0.0.1:5000,
//不過在服務器上是經過uwsgi設置端口,經過uwsgi來啓動項目,
//也就是說啓動了uwsgi,也就啓動了項目。
chdir = /home/www/ //項目目錄
json

wsgi-file = manage.py //flask程序的啓動文件,一般在本地是經過運行
// python manage.py runserver 來啓動項目的flask

callable = app //程序內啓用的application變量名服務器

processes = 4 //處理器個數app

threads = 2 //線程個數socket

stats = 127.0.0.1:9191 //獲取uwsgi統計信息的服務地址spa

3.保存配置文件,咱們能夠經過鍵入 uwsgi uwsgiconfig.ini 來啓動uwsgi線程

4.安裝nginx

5.修改nginx配置好文件

events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;

server {
listen 80; //默認的web訪問端口
server_name xxx.xxx.xxx.xxx; //你的公網ip
#charset koi8-r;
access_log /home/www/WebBlogold/logs/access.log; //服務器接收的請求日誌,
//須要在項目文件夾下建立
//logs文件夾,下同。
error_log /home/www/WebBlogold/logs/error.log; //錯誤日誌

location / {

include uwsgi_params; //這裏是導入的uwsgi配置

uwsgi_pass 127.0.0.1:8001; //須要和uwsgi的配置文件裏socket項的地址
//相同,不然沒法讓uwsgi接收到請求。

uwsgi_param UWSGI_PYHOME /home/www/WebBlogold/venv; //python的位置(虛擬環境下)

uwsgi_param UWSGI_CHDIR /home/www/WebBlogold; //項目根目錄

uwsgi_param UWSGI_SCRIPT manage:app; //啓動項目的主程序(在本地上運行
//這個主程序能夠在flask內置的
//服務器上訪問你的項目)

}
}
}
下面是一堆#,全都是註釋,不用管它。

6.啓動nginx,uwsgi便可

相關文章
相關標籤/搜索