安装uWSGI
进入虚拟环境venv,安装uwsgi (venv) [root@slave 192.168.11.64 /opt]$pip3 install uwsgi
检查uwsgi版本
(venv) [root@slave 192.168.11.64 /opt]$uwsgi --version
2.0.17.1
#检查uwsgi python版本
uwsgi --python-version
运行简单的uWSGI
#启动一个python uwsgi --http :8000 --wsgi-file test.py
http :8000
: 使用http协议,端口8000wsgi-file test.py
: 加载指定的文件,test.py
#test.py def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello World"] # python3
uWsgi热加载python程序
在启动命令后面加上参数 uwsgi --http :8088 --module mysite.wsgi --py-autoreload=1
#发布命令
command= /home/venv/bin/uwsgi --uwsgi 0.0.0.0:8000 --chdir /opt/mysite --home=/home/venv --module mysite.wsgi
#此时修改django代码,uWSGI会自动加载django程序,页面生效
运行django程序
#mysite/wsgi.py 确保找到这个文件
uwsgi --http :8000 --module mysite.wsgi
module mysite.wsgi
: 加载指定的wsgi模块
uwsgi配置文件
uwsgi支持ini、xml等多种配置方式,本文以 ini 为例, 在/etc/目录下新建uwsgi_nginx.ini,添加如下配置: # mysite_uwsgi.ini file [uwsgi] # Django-related settings # the base directory (full path)
# 项目的绝对路径的第一层路径 chdir = /opt/mysite # Django's wsgi file
# Django的wsgi.py文件相对路劲 module = mysite.wsgi # the virtualenv (full path)
# 虚拟环境解释器的绝对路劲 home = /opt/venv # process-related settings # master master = true # maximum number of worker processes
# 指定uwsgi启动的进程数 processes = 1 # the socket (use the full path to be safe
# socket指的是uwsgi启动一个socket链接,当你使用nginx+uwsgi的时候,使用socket参数!!!!!!!!!!!!!! # socket = 0.0.0.0:8000
# http 这个参数是uwsgi启动一个http连接,当你不用nginx只用uwsgi的时候,使用这个参数
http = 0.0.0.0:8000 # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum = true