nginx+uwsgi+ubuntu 部署django
配置uwsgi
新建一个myweb_uwsgi.ini 文件来配置uwsgi
# myweb_uwsgi.ini file
[uwsgi]
# Django-related settings
socket = :8000
# the base directory (full path)
chdir = /root/gf_global
# Django s wsgi file
module = gf_global.wsgi
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
#python文件变更时,重启uwsgi服务
python-autoreload=1
配置完成之后,直接使用命令启动
uwsgi --ini myweb_uwsgi.ini 直接启动uwsgi
配置nginx
/etc/nginx/sites-enabled/ 中的default文件
# /etc/init.d/nginx restart 重启nginx的命令
server {
listen 8099;
server_name 127.0.0.1
charset UTF-8;
access_log /var/log/nginx/myweb_access.log;
error_log /var/log/nginx/myweb_error.log;
client_max_body_size 75M;
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:8000;
uwsgi_read_timeout 2;
}
location /static {
expires 30d;
autoindex on;
add_header Cache-Control private;
alias /root/gf_global/templates/;
}
}
使用命令重新启动 nginx
/etc/init.d/nginx restart
如果启动失败,注意查看nginx 的报错文件,
在/etc/nginx nginx.conf文件下,注意将
#user www-data;
改为
user root ; 可解决权限不足问题
现在就可以访问你的的django服务 端口为8099
部署之后 admin 样式可能会丢失 ,可以按照下面的方式进行修改
http://blog.csdn.net/a657941877/article/details/8953233
http://www.jianshu.com/p/e6ff4a28ab5a