linux web服務器搭建 python flask + mysql + uwsgi + nginx --- 項目配置

1. Flask配置

virtualenv

 

sudo pip install virtualenv
mkdir projects
cd projects
virtualenv venv

git clone

git clone 'xxxxxxxxxx'

   導入項目使用的包

pip install -r requirement.txt

2. 數據庫導入

  之前已經dump了數據庫了,現在直接導入

mysql  -uroot -pyourpassword
create database xxx default charset utf8mb4;
use xxx;
source xxx/xxx/xxx.sql; # 導入之前到處的數據庫

3. vscode 配置

  安裝python插件

插件: python
來自 Microsoft

4. uwsgi

sudo pacman -S uwsgi
# 還需要一個插件
sudo pacman -S uwsgi-plugin-python
# 配置
[uwsgi]
# 工作路徑
chdir=/home/iangong/Projects/Starry
# python 路徑
home=/home/iangong/Projects/venv
# py入口文件
wsgi-file=/home/iangong/Projects/Starry/manager.py
# 入口 application
callable=app
# 是否啓動master進程
master=true
# worker進程數量
processes=1
# 每個進程的線程數
threads=2
# 生成用於通訊的socket,如與nginx進行通訊
#socket=/home/iangong/Projects/Starry/starry.sock
# 監聽地址和端口, 當與nginx一起用時,這裏不能監聽,要交給nginx
http-socket=127.0.0.1:7799
# 存放進程id的文件
pidfile=/home/iangong/Projects/Starry/starry.pid
# 統計查看端口
stats = 127.0.0.1:7800
# 開啓多線程
enable-threads=true
# master進程記錄進log
log-master=true,
# preload 官方沒有查到用法,是在網上看到的用來解決apscheduler不能運行的問題
#preload=true
# 描述不是很清楚,沒有理解。但是可以讓apscheduler正常運行
lazy-apps=true
# log
daemonize=/home/iangong/Projects/Starry/logs/starry.log
# python插件
plugin=python
# 
threaded-log = true

5. nginx

 安裝

sudo pacman -S  nginx

配置

# 安裝 nginx
sudo pacman -S nginx
# 在默認配置文件中包含自己的配置
sudo vim /etc/nginx/nginx.conf
# 在keepalive 後面插入
include /conf.d/*.conf;

# 創建conf.d 文件夾
sudo mkdir /etc/nginx/conf.d

sudo vim /etc/nginx/conf.d/xxx.conf

#輸入下面內容
server{
    listen 80;
    server 127.0.0.1;
    
    location / {
        include uwsgi_params;
        uwsgi_pass http://127.0.0.1:7799;
    }

    location /static/ {
        alias ~/xxx/xxx/static/;
        expires 1d;
    }
}

# 設置nginx自己啓動
systemctl enable nginx
# 啓動nginx
systemctl start nginx

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章