Liunx Centos Django+gunicorn+nginx部署
第一步: 1.DEBUG改成False,只有关闭了调试模式,后面才能让nginx来寻找静态文件。 2.ALLOW_HOSTS,加入你的域名,(或,和)服务器ip。或者直接用"*" 3.设置STATIC_ROOT,建议可以直接设为os.path.join(BASE_DIR,'static/'),也就把文件夹在manage.py的根目录里。 4.执行python manage.py collectstatic,就会将所有静态文件都放到第三步中设置的文件地址中。 ????执行完第四步后,目录结构应该是这样
project/ ????--project/ ????????--__init__.py ????????--setting.py ????????--urls.py ????????--wsgi.py ????--templates/ ????--your?app/ ????--manage.py ????--static/ ????????--auth/ ????????--your?app/ ????????????--css/ ????????????--js/ ????????????--images/ Gunicorn ????1. 进入 ?project?根目录,如我的根目录为/opt/cxm/,然后执行下面代码 gunicorn?-w?3?-b?127.0.0.1:8080?project.wsgi:application Nginx 配置信息 server?{??? #?这个server标识我要配置了 listen?80;??#?我要监听那个端口 server_name?120.77.222.60?;??#?你访问的路径前面的url名称 access_log??/var/log/nginx/access.log??main;??#?Nginx日志配置 charset??utf-8;?#?Nginx编码 gzip?on;??#?启用压缩,这个的作用就是给用户一个网页,比如3M压缩后1M这样传输速度就会提高很多 gzip_types?text/plain?application/x-javascript?text/css?text/javascript?application/x-httpd-php?application/json?text/json?image/jpeg?image/gif?image/png?application/octet-stream;??#?支持压缩的类型 error_page??404???????????/404.html;??#?错误页面 error_page???500?502?503?504??/50x.html;??#?错误页面 #?指定项目路径uwsgi location?/?{???????? proxy_pass?http://120.77.222.60:8000; proxy_set_header?Host?$host; proxy_set_header?X-Real-IP?$remote_addr; proxy_set_header?X-Forwarded-For?$proxy_add_x_forwarded_for; } #?指定静态文件路径 location?/static/?{ alias??/opt/sdy/static/; index??index.html?index.htm; } } 常用命令: 启动Nginx通过Nginx访问
??/etc/init.d/nginx?start ??/etc/init.d/nginx?stop 这里有个命令configtest,Nginx配置是重启生效的,如果你修改完了,不知道对不对又担心影响其他人可以使用它测试 ??/etc/init.d/nginx?configtest 如果是生产环境的话Nginx正在运行,就不要直接stop start 或者 restart ?直接reload就行了,对线上影响最低 ??/etc/init.d/nginx?reload (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |