django + gunicorn +supervisord+gevent(??)+ nginx  [TODO]

http://rangochen.blog.51cto.com/2445286/1426620
http://www.ahlinux.com/start/base/22270.html
http://foofish.net/blog/18/django-deploy
http://gunicorn-docs.readthedocs.org/en/latest/run.html

gunicorn –bind 106.186.118.123:8001 wsgi:application
gunicorn –bind 106.186.118.123:8001 -w 3 wsgi:application [TODO]

————————————————————————
问:后台运行
答: 使用参数 –daemon
gunicorn –bind 106.186.118.123:8001 –daemon wsgi:application 【现在】
supervisor 【TODO】
————————————————————————

gunicorn –bind=0.0.0.0:8002 mysite.wsgi

sudo django-admin.py startproject mysite
sudo gunicorn –bind=0.0.0.0:8002 mysite.wsgi

————————————————————————
问:sudo gunicorn –bind 0.0.0.0:8002 wsgi:application
答:运行正常
————————————————————————

查看进程状态:http://process.saiwei.info/

控制命令:

  1. ##重新读取配置
  2. sudo supervisorctl reread
  3. ##启动服务
  4. sudo supervisorctl start gunicorn
  5. ##停止服务
  6. sudo supervisorctl stop gunicorn
  7. ##有问题就重启supervisor的总服务
  8. sudo service supervisor stop
  9. sudo service supervisor start

脚本:

#!/bin/bash

cd /home/www/vhost_car/parking

gunicorn -c deploy_config.py  wsgi:application

3. nginx 配置

server {
    listen 80;
    server_name server_domain_or_IP;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/user/myproject;
    }

    location / {
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://unix:/home/user/myproject/myproject.sock;
    }
}

参考:
https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-centos-7

 
参考:http://xiaorui.cc/2014/11/22/%E7%94%A8gunicorn%E5%92%8Cgevent%E6%8F%90%E9%AB%98python-web%E6%A1%86%E6%9E%B6%E7%9A%84%E6%80%A7%E8%83%BD/

http://www.simpleapples.com/2015/06/configure-nginx-supervisor-gunicorn-flask/ [ 重要]

http://beiyuu.com/vps-config-python-vitrualenv-flask-gunicorn-supervisor-nginx/[ 重要]

http://docs.gunicorn.org/en/latest/deploy.html [官方文档]

http://gunicorn-docs.readthedocs.org/en/19.3/deploy.html
https://github.com/benoitc/gunicorn/blob/master/examples/nginx.conf
https://gist.github.com/postrational/5747293

django uWSGI and Nginx

http://andrew-liu.gitbooks.io/django-blog/content/xiang_mu_yu_app.html

-------------------------------------------
问:How to stop uwsgi
答: sudo killall -s INT /usr/local/bin/uwsgi
参考:http://serverfault.com/questions/565903/how-to-stop-uwsgi-when-no-pidfile-in-config
-------------------------------------------
问:很多人推荐俺gunicorn 【TODO】
-------------------------------------------
问:更新代码后,及时生效 【TODO】
答:
参考:https://www.v2ex.com/t/182882
-------------------------------------------
问:后台运行
答:在尾部加上&(and)字符表示后台运行
uwsgi –ini my_blog_uwsgi.ini &
参考:http://www.xiaomastack.com/2014/09/12/uwsgi-django-nginx/
-------------------------------------------
问:
答:CONT 18 继续(与STOP相反, fg/bg命令)
STOP 19 暂停(同 Ctrl + Z)
-------------------------------------------
问:connect() to unix:///home/chenwei/workspace/PycharmProjects/helloworld/mysite.sock failed (13: Permission denied)
答:uwsgi –socket mysite.sock –wsgi-file test.py –chmod-socket=666
注: 666 测试成功,  664还是失败
-------------------------------------------
问:官方文档
答:http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html

https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-uwsgi-and-nginx-on-ubuntu-14-04

http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html 【重要】
-------------------------------------------
问: Server Error (500)
答:参考: http://www.cnblogs.com/xiami303/p/3341313.html