安装uwsgi
1.安装pip
可以参考这篇文章:http://www.jsxubar.info/install-pip.html
2.安装uwsgi
pip install uwsgi
3 测试uwsgi
-
在你的机器上写一个test.py
-
-
# test.py
-
def application(env, start_response):
-
start_response('200 OK', [('Content-Type','text/html')])
-
return "Hello World"
4.编写uwsgi启动配置文件
-
[root@host-192-168-1-56 devops]# more my.ini
-
[uwsgi]
-
socket=:8001
-
chdir=/svn/devops/devops ###项目目录
-
pythonapth=/usr/bin/python
-
processes=4
-
env=DJANGO_SETTINGS_MODULE=devops.settings ###指定 项目名.setting
-
module=devops.wsgi ###指定wsgi.py配置文件,该配置文件和setting在一个目录下
-
threads=0
-
master=true
-
daemonize=/tmp/uwsgi.log
-
pidfile=/tmp/uwsgi.pid
-
python-autoreload=true
-
buffer-size=51200
5.编写wsgi配置文件
-
[root@host-192-168-1-56 devops]# more devops/wsgi.py
-
"""
-
WSGI config for devops project.
-
-
It exposes the WSGI callable as a module-level variable named ``application``.
-
-
For more information on this file, see
-
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
-
"""
-
-
import os
-
-
from django.core.wsgi import get_wsgi_application
-
-
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "devops.settings")
-
-
application = get_wsgi_application()
6.配置nginx
-
配置文件
-
[root@host-192-168-1-56 devops]# more /usr/local/nginx/conf/vhost/blog.haodai.com.conf
upstream django {
server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}
server {
listen 8099;
server_name devops.XXX.net;
charset utf-8;
root /svn/devops/devops;
client_max_body_size 75M; # adjust to taste
location /static {
alias /svn/devops/devops/static; ---nginx调用项目的静态文件
expires 20d;
}
location / {
uwsgi_pass django; ---反向代理,简单写法直接写成uwsgi_pass 127.0.0.1:8001即可
include uwsgi_params;
}
access_log /home/wwwlogs/devops.log access;
}
7 启动,测试
-
启动uwsgi和nginx
-
[root@host-192-168-1-56 devops]# /usr/local/python/bin/uwsgi my.ini
-
[root@host-192-168-1-56 devops]# nginx -s reload
-
测试:
-

参考链接:
http://www.python88.com/topic/101/?page=2
http://www.python88.com/topic/124/
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29096438/viewspace-2134101/
,如需转载,请注明出处,否则将追究法律责任。