码迷,mamicode.com
首页 > 其他好文 > 详细

Django 生产环境部署-记录 nginx+uwsgi+Django

时间:2016-07-01 13:22:42      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

这几天一直研究django生产环境的部署,看了很多文章,都写的很好,有些时候只是环境不太一样,配置过程中出现了很多的问题,例如:

uwsgi  ---module   一直运行不起来,,加--file参数才可以。。。

----亲测可以运行-----

1.安装DJANGO,创建工程项目,确保python manage.py runserver 0.0.0.0:8080 能够正常启动


2.安装uwsgi ,

在你的机器上写一个test.py

# test.py
def application(env, start_response):
start_response(‘200 OK‘, [(‘Content-Type‘,‘text/html‘)])
return "Hello World"
然后执行shell命令:

uwsgi --http :8001 --file test.py
访问网页:

http://127.0.0.1:8001/

看在网页上是否有Hello World


3.测试uwsgi 与 Django 是否能够结合运行

uwsgi --http :8000 --chdir /opt/app/Django-1.9.2/django/MadKing/ --file wsgi.py

4.配置uwsgi 与 nginx 结合

nginx.conf配置:

server {
listen 53385;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;
access_log /opt/app/Django-1.9.2/django/MadKing/access_log;
error_log /opt/app/Django-1.9.2/django/MadKing/error_log;

location / {
root html;
uwsgi_pass 127.0.0.1:3400;
include /usr/local/nginx-1.7.12/conf/uwsgi_params; # the uwsgi_params file you installed
index index.html index.htm;
}
location /static {

root /opt/app/Django-1.9.2/django/MadKing; # your Django project‘s static files - amend as required
}
#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}


在Django工程下创建: madking_uwsgi.ini
madking_uwsgi.ini file
[uwsgi]

socket = 127.0.0.1:3400
# Django-related settings
# the django project directory (full path)
chdir = /opt/app/Django-1.9.2/django/MadKing
# Django‘s wsgi file
file = wsgi.py

# process-related settings
# master
master = true
# maximum number of worker processes
processes = 2

threads = 2
max-requests = 6000

# ... with appropriate permissions - may be needed
chmod-socket = 664
# clear environment on exit
vacuum = true
daemonize = /opt/app/Django-1.9.2/django/MadKing/uwsgi.log
----------------------------------------------------------------------------

启动 uwsgi --ini /opt/app/Django-1.9.2/django/MadKing/MadKing_uwsgi.ini


重启nginx ./nginx -s reload

 

Django 生产环境部署-记录 nginx+uwsgi+Django

标签:

原文地址:http://www.cnblogs.com/xuleiyang/p/5632467.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!