nginx+gunicorn+django
来源:互联网 发布:react native app.js 编辑:程序博客网 时间:2024/06/08 03:50
1下载(略过)
2配置gunicorn:
2.1 编写gunicorn文件:
gunicorn.sh
#!/bin/bashNAME="travel" #Name of the application (*)DJANGODIR=/path/to/app # Django project directory (*)SOCKFILE=/path/to/app/run/gunicorn.sock # we will communicate using this unix socket (*)NUM_WORKERS=3 # how many worker processes should Gunicorn spawn (*)DJANGO_SETTINGS_MODULE=travel.settings # which settings file should Django use (*)DJANGO_WSGI_MODULE=travel.wsgi # WSGI module name (*)echo "Starting $NAME as `whoami`"# Activate the virtual environmentcd $DJANGODIRsource /path/to/app/venv/bin/activateexport DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULEPATHONPATH=/path/to/venv/bin/python3export PYTHONPATH# Create the run directory if it doesn't existRUNDIR=$(dirname $SOCKFILE)test -d $RUNDIR || mkdir -p $RUNDIR# Start your Django Unicorn# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)exec /path/to/app/venv/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \ --name $NAME \ --workers $NUM_WORKERS \ --bind=unix:$SOCKFILE \ --log-level=debug# --user $USER # --bind=unix:$SOCKFILE
3配置nginx
3.1修改/etc/nginx/nginx.conf:
删除其中关于server的定义,保留include;
在/etc/nginx/conf.d中添加自定义文件 app_nginx.conf
upstream test_server { server unix:/path/to/app/run/gunicorn.sock fail_timeout=10s;}# This is not neccessary - it's just commonly used# it just redirects example.com -> www.example.com# so it isn't treated as two separate websitesserver { listen 80; server_name example.com; return 301 $scheme://www.example.com$request_uri; }server { listen 80; server_name www.example.com; client_max_body_size 4G; access_log /path/to/app/logs/nginx-access.log; error_log /path/to/app/logs/nginx-error.log warn; location /static/ { autoindex on; alias /path/to/app/static/; } location /media/ { autoindex on; alias /path/to/app/media/; } location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; if (!-f $request_filename) { proxy_pass http://test_server; break; } } #For favicon location /favicon.ico { alias /path/to/app/static/img/favicon.ico; } #For robots.txt location /robots.txt { alias /path/to/app/static/robots.txt ; } # Error pages error_page 500 502 503 504 /500.html; location = /500.html { root /path/to/app/static/; }}
3.2
重新载入nginx.conf并重启服务: nginx -s reload
service nginx restart
如果报错,错误为: open() “/somewhere” failed (13: Permission denied)
需要检查当前SELinux mode: getenforce
如果显示Enforcing
,则通过输入setenforce 0
将mode设置为Permissive
然后重新执行3.2步骤,不出意外的话则可以正常运行!
0 0
- 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部署
- nginx + gunicorn + virtualenv部署django
- nginx+django+gunicorn+gevent+supervisor
- Centos7配置Django+Gunicorn+Nginx
- [django]django 部署,gunicorn、virtualenv、nginx
- A Django setup using Nginx and Gunicorn
- django+nginx+supervisor+gunicorn+gevent 网站部署
- Mac下Django+gunicorn+Nginx服务器部署
- python+django+gunicorn+nginx的配置
- nginx+gunicorn+virtualenv部署django项目
- Django+gunicorn+Nginx环境的搭建
- Ie与JSTL
- TCP三次握手
- 初学mysql常用函数总结(1)
- Linux
- Servlet API 中文版
- nginx+gunicorn+django
- Android流媒体开发之-直播自定义列表
- eclipse插件OpenExplorer快速打开文件目录
- Qemu2.8特性浏览
- 有关数组API记忆技巧
- 《JavaScript 闯关记》之对象
- Android流媒体开发之-服务器图片的加载
- 唠唠jQuery
- Android流媒体开发之-直播自定义分类