系统: CentOS 7(阿里云)
版本: Python 3.8.5
# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel lrzsz tar make gcc gcc-c++ # yum install libffi-devel -y
下载:https://www.python.org/downloads/release/python-385/
[root@iZbp1ejocu3f7z7p55v87kZ home]# tar -zxvf Python-3.8.5.tgz
[root@iZbp1ejocu3f7z7p55v87kZ home]# cd ~
[root@iZbp1ejocu3f7z7p55v87kZ ~]# mkdir python
[root@iZbp1ejocu3f7z7p55v87kZ ~]# cd /home/Python-3.8.5
[root@iZbp1ejocu3f7z7p55v87kZ Python-3.8.5]# ./configure --prefix=’/root/python’
[root@iZbp1ejocu3f7z7p55v87kZ Python-3.8.5]# make
[root@iZbp1ejocu3f7z7p55v87kZ Python-3.8.5]# make install
[root@iZbp1ejocu3f7z7p55v87kZ bin]# vim ~/.bash_profile
[root@iZbp1ejocu3f7z7p55v87kZ bin]# source ~/.bash_profile
[root@iZbp1ejocu3f7z7p55v87kZ home]# pip3 install --upgrade pip
[root@iZbp1ejocu3f7z7p55v87kZ home]# yum install python3-devel
[root@iZbp1ejocu3f7z7p55v87kZ home]# pip3 install uwsgi
[root@iZbp1ejocu3f7z7p55v87kZ Python-3.8.5]# yum install nginx -y
[root@iZbp1ejocu3f7z7p55v87kZ Python-3.8.5]# systemctl start nginx
浏览器访问服务器地址:
Nginx 常用命令
# 设置 nginx 开机自启动 systemctl enable nginx # 开启 nginx systemctl start nginx # 查看 nginx 运行状态 systemctl status nginx # 关闭 nginx systemctl stop nginx # 重启 nginx systemctl restart nginx # 重载配置文件 systemctl reload nginx
[root@iZbp1ejocu3f7z7p55v87kZ Python-3.8.5]# pip3 install flask
开发环境下,项目环境依赖写入 requirement.txt
pip freeze >requirements.txt
将flask项目拷贝到服务器,安装 requirement.txt 所包含的依赖
[root@iZbp1ejocu3f7z7p55v87kZ moive_web]# pip3 install -r requirement.txt
安装 mysqlclient
[root@iZbp1ejocu3f7z7p55v87kZ moive_web]# yum install gcc mariadb-devel
[root@iZbp1ejocu3f7z7p55v87kZ moive_web]# pip3 install mysqlclient
在项目根目录下创建 uwsgi 配置文件
[root@iZbp1ejocu3f7z7p55v87kZ moive_web]# vim uwsgi.ini
# /var/www/conf/config.ini [uwsgi] # uwsgi 启动时所使用的地址与端口 socket = 127.0.0.1:8000 # python 调用的模块 module = app # python 启动程序文件 wsgi-file = /www/movie_web/app.py # python 程序内用以启动的 application 变量名 callable = app # 处理器数 processes = 4 # 线程数 threads = 8 # 输出日志文件 daemonize = /www/movie_web/log/server.log
启动 uwsgi
[root@iZbp1ejocu3f7z7p55v87kZ nginx]# cd /etc/nginx/conf.d
[root@iZbp1ejocu3f7z7p55v87kZ nginx]# vim default.conf
server { listen 80; server_name localhost; access_log /var/log/nginx/host.access.log main; location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8000; uwsgi_param UWSGI_CHDIR /www/moive_web; } }
[root@iZbp1ejocu3f7z7p55v87kZ moive_web]# systemctl reload nginx
[root@iZbp1ejocu3f7z7p55v87kZ moive_web]# systemctl restart nginx
浏览器访问服务器地址,大功告成~