1、安装uwsgi(如果 是python2直接pip安装,如果是python3则用pip3安装)
pip install uwsgi
2、 编辑测试文件,用于测试uwsgi是否能正常使用
vi test.py
def application(env,start_response):
start_response('200 OK',[('Content-Type','text/html')])
return ["hello world"]
3、#窗口启动uwsgi测试:
uwsgi --http :9090 --wsgi-file test.py
#在浏览器中打开http://127.0.0.1:9090
弹出hello world为正常。
4、编辑uwsgi配置文件:
vi /etc/uwsgi.ini
[uwsgi]
#使用nginx连接时使用
socket = 0.0.0.0:8080
master = true
enable-threads = true
workers = 1
processes = 4
threads = 2
wsgi-file = project1/wsgi.py
chdir = /home/darren/django/dailyfresh/
daemonize = /var/log/uwsgi9090.log
[uwsgi]
socket = 192.168.1.121:9090
master = true
vhost = true #多站模式
workers = 2
reload-mercy = 10
vacuum = true #退出重启会清理文件
max-requests = 1000
limit-as = 512
buffer-size = 30000
chmod-socket = 666
wsgi-file = project1/wsgi.py
chdir = /home/darren/django/project1/
pidfile = /var/run/uwsgi.pid
#daemonize = /var/log/uwsgi.log
5、启动uwsgi
uwsgi --ini /etc/uwsgi.ini
6、nginx配置
server {
listen 80;
server_name localhost;
access_log logs/host.access.log main;
location / {
#root /home/darren/django/project1;
index index.html index.htm;
include uwsgi_params;
uwsgi_pass 192.168.1.121:9090;
}
运行时可能出现的错误:
明天再写