国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python Web程序部署到Ubuntu服務器上的方法

2020-02-22 23:17:00
字體:
來源:轉載
供稿:網友

在本文記錄了我在Ubuntu中部署Flask Web站點的過程, 其中包括用戶創建、代碼獲取、Python3環境的安裝、虛擬環境設置、uWSGI啟動程序設置,并將Nginx作為前端反向代理。希望對各位有所幫助。

建立一個Python Web程序專用賬戶

adduser haseovim /etc/sudoers #將haseo用戶加入導sudo用戶清單中sudo usermod -a -G www-data haseo

安裝Python3并配置程序運行環境

1.更新Ubuntu的軟件庫

sudo apt-get updatesudo apt-get -y upgradesudo apt-get install build-essential libssl-dev libffi-dev python3-dev #安裝一些必要的工具包

2.安裝python包管理工具

python3 -Vsudo apt-get install -y python3-pippip3 install virtualenv

配置Python 程序

1.創建程序目錄

mkdir -p /var/www/html/pricing-service

2.修改目錄權限

sudo chown haseo:haseo /var/www/html/pricing-service

3.創建一個SSH Key使得用戶可以同步GitHub的代碼

ssh-keygencat ~/.ssh/id_rsa.pub # 復制公鑰并增加到GitHub(https://github.com/settings/keys)

4.復制GitHub上的代碼

git clone git@xxx .

5.創建log目錄

mkdir log

6.創建虛擬目錄

pip3 install virtualenvpython3 -m virtualenv venv # 在pricing-service目錄下執行./venv/bin/pip install -r requirements.txt./venv/bin/pip install uwsgi

配置uwsgi

1.測試一下python直接運行程序是否可以訪問

vim ~/myproject/wsgi.pyfrom flask import Flaskapp = Flask(__name__)@app.route("/")def hello(): return "<h1 style='color:blue'>Hello There!</h1>"if __name__ == "__main__": app.run(host='0.0.0.0')python wsgi.py

2.創建WSGI入口文件

vim ~/myproject/wsgi.pyfrom myproject import appif __name__ == "__main__": app.run()

3.測試uWSGI是否正常運行

uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:app

4.創建uWSGI配置文件

前面測試沒問題之后我們開始創建uWSGI配置文件

vim ~/myproject/wsgi.ini[uwsgi]module = wsgi:appmaster = trueprocesses = 5socket = socket.sockchmod-socket = 660vacuum = truedie-on-term = true

5.創建systemd文件

sudo vim /etc/systemd/system/price_service.service[Unit]Description=uWSGI instance to serve price_serviceAfter=network.target[Service]User=haseoGroup=www-dataWorkingDirectory=/var/www/html/pricing-serviceEnvironment="PATH=/var/www/html/pricing-service/venv/bin"ExecStart=/var/www/html/pricing-service/venv/bin/uwsgi --ini wsgi.ini[Install]WantedBy=multi-user.target            
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 房产| 洪泽县| 永安市| 咸丰县| 双柏县| 米脂县| 乐平市| 会同县| 象山县| 株洲县| 图木舒克市| 陕西省| 溧阳市| 醴陵市| 海兴县| 共和县| 台东县| 灵台县| 乌鲁木齐县| 阳江市| 明水县| 夏河县| 阳城县| 岫岩| 凤凰县| 兰西县| 雷波县| 育儿| 阿巴嘎旗| 瑞金市| 济源市| 东兰县| 定西市| 寻乌县| 辉南县| 拉萨市| 崇文区| 富阳市| 得荣县| 阜康市| 应用必备|