1.云服务器:
三丰云_免费云服务器_高防服务器_vps云主机服务商 https://www.sanfengyun.com
首页---->三丰云---->免费虚拟主机
或 三丰云---->免费云服务器CPU 1G,内存10G。
2.1教程链接:
flask部署 ngnix+uwsgi+flask搭建网站_哔哩哔哩_bilibili
2.2作者博客:
flask + nginx + uWSGI部署_Idea King的博客-CSDN博客_flask nginx
3.补充:
可使用,宝塔面板在软件商店下载python项目
4.笔迹:
1.安装宝塔面板
宝塔Linux面板安装教程 - 2022年2月18日更新 - 7.9.0正式版 - Linux面板 - 宝塔面板论坛
Centos安装命令:
|
Complete! Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service. success ================================================================== Congratulations! Installed successfully! ================================================================== 外网面板地址: 宝塔Linux面板 内网面板地址: 宝塔Linux面板 username: 3s5cwxqy password: 4de0ae84 If you cannot access the panel, release the following panel port [8888] in the security group 若无法访问面板,请检查防火墙/安全组是否有放行面板[8888]端口 ================================================================== Time consumed: 5 Minute!
|
3.访问网址
LNMP安装
4.添加一个站点
cd /www/wwwroot/www.test.com www.test.com:5656 111.67.195.134:5656 |
5..安装python3(推荐使用python项目管理器)
which python mkdir /usr/local/python3 cd /usr/local/python3
安装依赖 yum -y groupinstall "Development tools" yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
安装python3(3.6.2) wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
蓝奏云下载:https://www.lanzous.com/i7x8kxg 密码:3bhk
tar -xvJf Python-3.6.2.tar.xz cd Python-3.6.2 ./configure --prefix=/usr/local/python3 make && make install
创建软链接 ln -s /usr/local/python3/bin/python3 /usr/bin/python3 ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 |
6.搭建web环境
6.1 创建虚拟环境, 安装flask
cd /www/wwwroot mkdir test cd test
pip3 install --upgrade virtualenv pip3 install --upgrade pip ln -s /usr/local/python3/bin/virtualenv /usr/bin/virtualenv virtualenv -p python3 .env 进入虚拟环境安装flask source .env/bin/activate pip3 install flask deactivate |
6.2写一个简单的测试程序test.py
# Vi test.py # python3 test.py
from flask import Flask
app = Flask(__name__)
@app.route("/") def helloWorld(): return "Hello World"
if __name__ == '__main__': app.run(host='0.0.0.0', port=8787, debug=True)
|
6.3 安装和配置uwsgi
pip3 install uwsgi find / -name uwsgi ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi |
# vi uwsgi.ini
[uwsgi] chdir=/www/wwwroot/test # 工程目录 home=/www/wwwroot/test/.env # 虚拟环境目录 module=test # 启动flask应用的文件名,不用加.py callable=app # 应用名,与我们hell master=true processes=2 # worker的进程个数 chmod-socket=666 logfile-chmod=644 procname-prefix-spaced=test # uwsgi的进程名称前缀,启动后可通过ps -ef | grep test查找到这个进程 py-autoreload=1 #py文件修改,自动加载,也就是设置热启动了 #http=0.0.0.0:8080 #监听端口,测试时使用
vacuum=true # 退出uwsgi是否清理中间文件,包含pid、sock和status文件 socket=%(chdir)/uwsgi/uwsgi.sock # socket文件,配置nginx时候使用 stats=%(chdir)/uwsgi/uwsgi.status # status文件,可以查看uwsgi的运行状态 pidfile=%(chdir)/uwsgi/uwsgi.pid # pid文件,通过该文件可以控制uwsgi的重启和停止 daemonize=%(chdir)/uwsgi/uwsgi.log # 设置后台模式,然后将日志输出到uwsgi.log。当调试时,可先注释掉此内容 ***************************************************************************
********************************************************************************** [uwsgi] chdir=/www/wwwroot/test home=/www/wwwroot/test/.env module=test callable=app master=true processes=2 chmod-socket=666 logfile-chmod=644 procname-prefix-spaced=test py-autoreload=1 #http=0.0.0.0:8080
vacuum=true socket=%(chdir)/uwsgi/uwsgi.sock stats=%(chdir)/uwsgi/uwsgi.status pidfile=%(chdir)/uwsgi/uwsgi.pid daemonize=%(chdir)/uwsgi/uwsgi.log |
6.4手动创建uwsgi运行所需要的文件
mkdir uwsgi cd uwsgi
touch uwsgi.pid touch uwsgi.sock touch uwsgi.status touch uwsgi.log cd ..
# cd uwsgi # vi uwsgi.pid # vi uwsgi.sock # vi uwsgi.status # vi uwsgi.log
mv uwsgi.pid mv uwsgi.sock mv uwsgi.status mv uwsgi.log
# rm uwsgi.pid # rm uwsgi.sock # rm uwsgi.status # rm uwsgi.log
|
6.5uwsgi 常用命令
uwsgi --ini uwsgi.ini # 启动 uwsgi --reload uwsgi.pid # 重启 uwsgi --stop uwsgi.pid # 关闭 /www/wwwroot/drop/1_sayhello/sayhello |
6.6配置nginx
location / { include uwsgi_params; uwsgi_pass unix:/www/wwwroot/test/uwsgi/uwsgi.sock; } |
7.git 下载一个项目进行部署
mkdir sayhello cd sayhello git init
git config --global https.proxy git config --global --unset https.proxy # git clone GitHub - greyli/sayhello: A simple message board application build with Flask.
git config --global url."https://gitclone.com/".insteadOf https://git clone https://github.com/tendermint/tendermint.git
ping github.com # cd /etc # vi hosts 199.232.69.194 github.global.ssl.fastly.net 140.82.114.4 github.com
# service network restart |
python3 -m venv env source env/bin/activate pip3 install -r requirements.txt pip list # pip3 list |
8.flask启动
flask forge flask run --host 0.0.0.0 |
5.1
- 2.xshell连接查看密码等信息