Liunx Centos Django+gunicorn+nginx部署
发布时间:2020-05-24 03:45:32 所属栏目:Linux 来源:互联网
导读: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/ --yourapp/ --manage.py --static/ --auth/ --yourapp/ --css/ --js/ --images/ Gunicorn 1. 进入 project根目录,如我的根目录为/opt/cxm/,然后执行下面代码 gunicorn-w3-b127.0.0.1:8080project.wsgi:application Nginx 配置信息 server{
#这个server标识我要配置了
listen80;#我要监听那个端口
server_name120.77.222.60;#你访问的路径前面的url名称
access_log/var/log/nginx/access.logmain;#Nginx日志配置
charsetutf-8;#Nginx编码
gzipon;#启用压缩,这个的作用就是给用户一个网页,比如3M压缩后1M这样传输速度就会提高很多
gzip_typestext/plainapplication/x-javascripttext/csstext/javascriptapplication/x-httpd-phpapplication/jsontext/jsonimage/jpegimage/gifimage/pngapplication/octet-stream;#支持压缩的类型
error_page404/404.html;#错误页面
error_page500502503504/50x.html;#错误页面
#指定项目路径uwsgi
location/{
proxy_passhttp://120.77.222.60:8000;
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
}
#指定静态文件路径
location/static/{
alias/opt/sdy/static/;
indexindex.htmlindex.htm;
}
}
常用命令: 启动Nginx通过Nginx访问 /etc/init.d/nginxstart /etc/init.d/nginxstop 这里有个命令configtest,Nginx配置是重启生效的,如果你修改完了,不知道对不对又担心影响其他人可以使用它测试 /etc/init.d/nginxconfigtest 如果是生产环境的话Nginx正在运行,就不要直接stop start 或者 restart 直接reload就行了,对线上影响最低 /etc/init.d/nginxreload (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
