fastcgi方式部署Django
首先你需要安装 nginx
yum install nginx
然后需要安装一个 python 包 叫 “flup”他是类似php-FPM的东西,作用是管理fastCGI分配请求到 各个常驻进程
pip install flup
使用 runfgi 参数 启动django 服务线程
python ./manage.py runfcgi host=127.0.0.1 port=8080
配置你的nginx
server {
listen 80;
server_name myhostname.com;
access_log /var/log/nginx/sample_project.access.log;
error_log /var/log/nginx/sample_project.error.log;
# https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-production
location /static/ { # STATIC_URL
alias /home/www/myhostname.com/static/; # STATIC_ROOT
expires 30d;
}
location /media/ { # MEDIA_URL
alias /home/www/myhostname/static/; # MEDIA_ROOT
expires 30d;
}
location / {
include fastcgi_params;
fastcgi_pass 127.0.0.1:8080;
}
}
从新启动nginx
/etc/init.d/nginx reload
uWSGI方式部署Django
首先你需要安装 uWSGI:
yum install epel-release uWSGI
然后配置到你的目录端口等信息:
uwsgi --socket 127.0.0.1:9003 --processes 2
--chdir /webroot/record/record --pp .. -w wsgi
--daemonize /weblog/record.log
配置你的nginx
server {
listen 80;
server_name _;
location /static/ { # STATIC_URL
alias /webroot/static/; # STATIC_ROOT
expires 30d;
}
location /media/ { # MEDIA_URL
alias /usr/share/django-project/djtest/djtest/static/; # MEDIA_ROOT
expires 30d;
}
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9001;
}
}
从新启动nginx
/etc/init.d/nginx reload