首页 > 代码库 > Django Nginx配置

Django Nginx配置


1、安装uwsgi、flup、django
wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz

2、项目创建和配置
2.1、创建项目

cd /root/codes/django-admin.py startproject myproject

2.2、创建/root/codes/uwsgi.xml

<uwsgi>      <socket>0.0.0.0:8001</socket>      <pythonpath>/root/codes/myproject</pythonpath>    <module>django_wsgi</module>    <profiler>true</profiler>      <memory-report>true</memory-report>      <enable-threads>true</enable-threads>      <logdate>true</logdate>      <limit-as>6048</limit-as>  </uwsgi> 

2.3、创建/root/codes/django_wsgi 

import osimport django.core.handlers.wsgios.environ[DJANGO_SETTINGS_MODULE] = myproject.settings #"项目名.settings"application = django.core.handlers.wsgi.WSGIHandler()

 

2.5、nginx 配置

可以直接修改/etc/nginx/nginx.conf或者在conf.d中添加一个conf后缀的文件,配置如下:

    location ~ /zhaoshihui {        #include uwsgi_params;        #uwsgi_pass 127.0.0.1:8001;        fastcgi_pass 127.0.0.1:8001;        root  /root/codes/zhaoshihui/;    }

 

2.6、创建启动和重启脚本/root/codes/run.sh

#!/bin/bashps -efa | grep "port=8001" | grep -v "grep port=8001" | awk ‘$3==1 {print "kill -9 " $2}‘ | shpython manage.py runfcgi host=127.0.0.1 port=8001ps -efa | grep "port=8001" | grep -v "grep port=8001"

 

3、启动应用
sh /root/codes/run.sh

4、在浏览器中访问
http://服务器ip/myproject

 


Django Nginx配置