最簡單的uwsgi+nginx配置多個django站點


1. nginx.conf

  http{

    server

    {

      listen       80;

      server_name  www.web1.com

      .......

      location /

      {

        uwsgi_pass 127.0.0.1:8000;

        .......

      }

    }

    server

    {

      listen       80;

      server_name  www.web2com

      .......

      location /

      {

        uwsgi_pass 127.0.0.1:8001;

        .......

      }

    }

 }

nginx配置文件建立兩個server,分別將域名請求轉發至服務器兩個本地端口。

 

2.uwsgi

  為每個站點配置各自的配置文件,在此使用的xml格式的配置文件。ps:如果uwsgi可以像nginx一樣一個配置文件搞定,就太美了。

  /opt/site1/djangoUwsgi.xml

  <uwsgi>

    <socket>127.0.0.1:8000</socket>

    <listen>80</listen>

    .......

  </uwsgi>

 

  /opt/site2/djangoUwsgi.xml

  <uwsgi>

    <socket>127.0.0.1:8001</socket>

    <listen>80</listen>

    .......

  </uwsgi>

 

3.配置文件搞定,啟動

  uwsgi -x /opt/site1/djangoUwsgi.xml

  uwsgi -x /opt/site2/djangoUwsgi.xml

  nginx -c /opt/nginx.conf

 

4.關閉

  killall -QUIT uwsgi ,這樣會殺死所有的站點uwsgi進程,可能有需要殺各自的進程

  @N t s同學給出了linux shell方法,在此感謝。

  line=`ps aux|grep uwsgi |grep 'uwsgi ./site1/.'|awk '{print $2}' `

  for pid in line;

  do

      kill -9 $pid;

  done

  作用是查看相關進程,取出進程號,挨個殺死。名字和字段數字可以按自己系統,自行設置。

 

附:uwsgi自動重啟參數:<py-autoreload>1</py-autoreload>

      官網還有其它參數:py-auto-reload    python-auto-reload    python-autoreload    py-auto-reload-ignore, 詳見http://uwsgi-docs.readthedocs.org/en/latest/Options.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM