django1.8+uwsgi+nginx+supervisord部署項目筆記

學這個搞了我2天。最好的東西學會了怎排除問題。html

 

echo_supervisord_conf > /etc/supervisord.confpython

直接貼代碼,我同時部署2個項目,一個直接返回' hello',另外一個空。nginx

hello 項目:web

/root/27env/hello/uwsgi.ini:django

##################################dom

[uwsgi]socket

vhost = false學習

plugins = pythonui

socket = 127.0.0.1:8080this

master = true

enable-threads = true

workers = 1

wsgi-file = /root/27env/hello/hello/wsgi.py

chdir = /root/27env/hello

########################

/etc/nginx/sites-available/hello.conf

###########################

upstream django {

     server unix:///path/to/your/mysite/mysite.sock; # for a file socket

    server 127.0.0.1:8080; # for a web port socket (we'll use this first)

}

# configuration of the server

server {

    # the port your site will be served on

    listen      8000;

    # the domain name it will serve for

    #server_name http://120.25.146.222:8000/; # substitute your machine's IP address or FQDN

    charset     utf-8;

 

    # max upload size

    client_max_body_size 75M;   # adjust to taste

 

    # Django media

    # location /media  {

    #     alias /path/to/your/mysite/media;  # your Django project's media files - amend as required

    #  }

 

    # location /static {

    #    alias /path/to/your/mysite/static; # your Django project's static files - amend as required

    # }

 

    # Finally, send all non-media requests to the Django server.

    location / {

        uwsgi_pass  django;

        include     uwsgi_params; # the uwsgi_params file you installed

    }

}

###################################

須要執行sudo ln -s /etc/nginx/sites-available/zqxt.conf /etc/nginx/sites-enabled/zqxt.conf

啓動nginx :

service nginx start

啓動uwsgi :

uwsgi: --ini uwsgi.ini

使用supervisord管理:

/etc/supervisord.conf:

文件末端添加:

 

[program:hello]

command=/root/.pyenv/shims/uwsgi --ini /root/27env/hello/uwsgi.ini

directory=/root/27env/hello

startsecs=0

stopwaitsecs=0

autostart=true

autorestart=true

[program:wx]

command=/root/.pyenv/shims/uwsgi --ini /root/27env/wx/weixin_project/weixin_project/uwsgi.ini

directory=/root/27env/wx/weixin_project

startsecs=0

stopwaitsecs=0

autostart=true

autorestart=true

執行:supervisord -c /etc/supervisord.conf

操控:  supervisorctl

...

 

 

weixin_project:

uwsgi:

[uwsgi]

vhost = false

plugins = python

socket = 127.0.0.1:8001

master = true

enable-threads = true

workers = 4

wsgi-file = /root/27env/wx/weixin_project/weixin_project/wsgi.py

chdir = /root/27env/wx/weixin_project

nginx配置:

server{

    listen    8002;

    

    charset   utf-8;

    client_max_body_size    75M;

    location /{

        uwsgi_pass  127.0.0.1:8001;

        include    uwsgi_params;

        uwsgi_connect_timeout    30;

}

}

。外網訪問地址:http://120.25.146.222:8000/

http://120.25.146.222:8002/

相關學習資料:http://uwsgi-docs.readthedocs.org/en/latest/tutorials/Django_and_nginx.html#configure-nginx-for-your-site

http://www.jianshu.com/p/e6ff4a28ab5a

相關文章
相關標籤/搜索