nginx+gunicorn+django
2016-12-23 23:33
344 查看
1下载(略过)
2配置gunicorn:
2.1 编写gunicorn文件:
gunicorn.sh
3配置nginx
3.1修改/etc/nginx/nginx.conf:
删除其中关于server的定义,保留include;
在/etc/nginx/conf.d中添加自定义文件 app_nginx.conf
3.2
重新载入nginx.conf并重启服务:
如果报错,错误为:
需要检查当前SELinux mode:
如果显示
然后重新执行3.2步骤,不出意外的话则可以正常运行!
2配置gunicorn:
2.1 编写gunicorn文件:
gunicorn.sh
#!/bin/bash NAME="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 environment cd $DJANGODIR source /path/to/app/venv/bin/activate export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE PATHONPATH=/path/to/venv/bin/python3 export PYTHONPATH # Create the run directory if it doesn't exist RUNDIR=$(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 websites server { 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步骤,不出意外的话则可以正常运行!
相关文章推荐
- VPS环境搭建详解(Virtualenv+Gunicorn+Supervisor+Nginx+Django+Flask+oneapm+event
- CentOS6.5下Gunicorn+Django+nginx部署的过程
- django 部署,gunicorn、virtualenv、nginx
- nginx redirect to gunicorn for Django or Jetty/Tomcat
- apache(nginx)+django+virutalenv(virtualenvwrapper)+gunicorn+supervisor配置高效web环境
- django部署方式之Gunicorn+Django+nginx+mysql
- Nginx+Gunicorn+virtualenv+supervisord+Postgresql部署Django应用 推荐
- django+nginx+supervisor+gunicorn+gevent 网站部署
- Django笔记 生产环境部署 gunicorn+nginx+supervisor
- nginx + gunicorn + django的简单部署
- gunicorn + nginx + django
- ubuntu/linux nginx+Gunicorn+django 部署方法详细教程
- 云服务器之nginx+gunicorn+django+mysql部署
- 阿里云部署Django项目(超详细图文教程) —— Part2. 使用Nginx, Gunicorn, virtualenv, supervisor 部署Django应用
- Minimal Nginx and Gunicorn configuration for Django projects
- Django+nginx+gunicorn部署流程(二)
- django+nginx+supervisor+gunicorn+gevent 网站部署
- 初次部署django+gunicorn+nginx
- django+nginx+supervisor+gunicorn+gevent 网站部署
- Setting up Django with Nginx, Gunicorn, virtualenv, supervisor and PostgreSQL