在Centos 7 系統上部署flask 項目 pipenv+nginx+gunicorn

1.安裝python

https://www.cnblogs.com/changtao/articles/10539287.html

2.安裝mysql數據庫

https://www.cnblogs.com/changtao/articles/10539299.html

3.安裝nginx

# 切換到 /usr/local/src
cd /usr/local/src
# 下載nginx 安裝包
wget http://nginx.org/download/nginx-1.6.2.tar.gz
# 解壓
tar zxvf nginx-1.6.2.tar.gz
# 切換到 nginx-1.6.2
cd nginx-1.6.2
# 檢查配置
./configure --prefix=/usr/local/nginx
# 編譯而且編譯安裝
make && make install
# 創建service 服務
vim  /lib/systemd/system/nginx.service 
--------------------------------------------
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true 
[Install]
WantedBy=multi-user.target
----------------------------------------------
# 啓動nginx
systemctl start nginx.service
# 設置開機啓動
systemctl enable nginx.service
# 修改配置文件
vim /usr/local/nginx/config/nginx.conf
----------------------------------------------
http 里加 
upstream movie {
        server 127.0.0.1:5000;
}
​
server 里加
location \ {
    proxy_pass http://movie;
}
注意: nginx 默認的啓動配置文件是 /usr/local/nginx/sbin/nginx

nginx啓動時如何指定配置文件?????????????

4.在linux下載pipenv

pip inseall pipenv

pipenv install 初始化虛擬環境

pipenv install -r 依賴的文件名 下載依賴包

5.在lrzsz 便於linux 傳輸文件

yum install lrzsz -y (linux安裝文件拖動軟件,能夠方便的在windows linux之間傳輸文件)html

lrzsz工具提供了倆命令, rz(接收資源) sz(發送資源)python

6.在開發環境中導出項目的依賴模塊

pipenv freeze > 文件 // pip freeze > ***.txtmysql

7.下載 gunicorn

pip install gunicorn
# -w 綁定線程數
# -b 綁定ip+port
# server 啓動文件
# app flask的核心對象
gunicorn -w 4 -b 127.0.0.1:9000  server:app

8.注意:nginx 配置文件的路徑,使用gunicorn啓動項目時,server:app server不能和APP重名!!!!

相關文章
相關標籤/搜索