python+django+gunicorn+nginx的配置
来源:互联网 发布:人工智能市场规模 编辑:程序博客网 时间:2024/06/05 17:38
CentOS7下用gunicorn和nginx来部署python项目就比apache容易多了
python,django,gunicorn的安装及新建一个django项目上一节详细讲解了.
一些开发环境的依赖包需要安装,上一节也已经详细讲解了.
编译安装nginx.以稳定版的nginx1.8为例:
tar -zxvf nginx-1.8.0.tar.gzcd nginx-1.8.0./configure # 默认安装在/usr/local/niginxmakemake install
安装完毕后,使用命令whereis nginx
查看是否安装成功
配置nginx:
nginx的默认配置文件是/usr/local/nginx/conf/nginx.conf
,为了个更灵活的配置和使用nginx,我们另外再新建一个配置文件.在项目文件p1里新建mime.types
(文件内容为空)和nginx.conf
,编辑nginx.conf:
user qiu;events { worker_connections 1024; accept_mutex off; }http { include mime.types; default_type application/octet-stream; sendfile on; upstream app_server { server unix:/tmp/gunicorn.sock fail_timeout=0; } server { listen 80; client_max_body_size 4G; server_name example.com www.example.com; keepalive_timeout 5; root /path/to/app/current/public; location / { try_files $uri @proxy_to_app; } location @proxy_to_app { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://127.0.0.1:8888; } error_page 500 502 503 504 /500.html; location = /500.html { root /path/to/app/current/public; } }}
很多配置使用默认的就行,最主要的是把请求转发到8888端口.
启动nginx和gunicorn:
可以看到,配置文件里,nginx监听80端口,代理和转发8888端口.所以gunicorn使用8888端口就行了.
启动nginx: /usr/local/nginx/sbin/nginx -c /home/qiu/workspace/p1/nginx.conf
在p1目录里启动gunicorn: /usr/local/python2711/bin/gunicorn p1.wsgi:application -b 127.0.0.1:8888
然后在浏览器里输入[ip]/admin就可以看到django的管理界面了.
0 0
- python+django+gunicorn+nginx的配置
- Centos7配置Django+Gunicorn+Nginx
- django nginx 与 gunicorn入门级配置
- Django+gunicorn+Nginx环境的搭建
- nginx + gunicorn + django的简单部署
- centos6 nginx + gunicorn + django的简单部署
- nginx+gunicorn运行django
- nginx+gunicorn+django
- Nginx + Gunicorn(+gevent) + Django
- gunicorn + nginx + django
- django + gunicorn + nginx 部署
- nginx+gunicorn+django
- django+gunicorn+nginx
- nginx+gunicorn+django部署
- 【Python】Centos7下部署Django(nginx+gunicorn)
- django gunicorn启动配置
- nginx + gunicorn + virtualenv部署django
- nginx+django+gunicorn+gevent+supervisor
- java map 的用法
- copy内存管理(二)
- yii2自定义组件
- 迎接2016
- HDU 1031 Design T-Shirt【排序】
- python+django+gunicorn+nginx的配置
- Android Volley完全解析(四),带你从源码的角度理解Volley
- online_judge_1158
- How-old 刷脸
- Android 图片的内存优化
- Unity5脚本事件函数及其执行顺序
- Nokia 920硬刷win10
- win64位 安装python opencv
- Linux学习之路-02-Ubuntu系统关闭独显+省电降温设置