这几天一直研究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