首頁>技術>

使用gunicorn作為django的wsgi server.安裝

pip install gunicorn
建立與django的聯絡配置檔案:config.py
# gunicorn_config.py chdir = '/export/idcs/app/idcInstall' #gunicorn要切換到的目的工作目錄 timeout = 30 #超時 workers = 1 #程序數 threads = 1 #指定每個程序開啟的執行緒數
啟動gunicorn
/export/idcs/app/bin/python3 /export/idcs/capp/bin/gunicorn -c config,py --bind unix:idcsProd.sock idcInstall.wsgi --reload --access-logfile -
nginx設定連線gunicorn
upstream app_server {    # server unix:///path/to/your/mysite/mysite.sock; # for a file socket    server unix:/export/idcs/app/idcInstall/idcsProd.sock;}location @proxy_to_app {             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #轉發中加入客戶端地址             proxy_set_header X-Forwarded-Proto $scheme;   #轉發中加入scheme             proxy_set_header Host $http_host;  #設定訪問的server伺服器名稱            # we don't want nginx trying to do something clever with            # redirects, we set the Host: header above already.             proxy_redirect off; #關閉所有其它設定             proxy_pass http://app_server;      }
在superviord的中管理gunicron安裝
pip install supervisor==4.2.0
使用supervisor管理gunicorn
echo_supervisord_conf  > supervisord.confchmod 755 /export/project1/project/gunicorn.sh修改program的部分[program:project1]command = /export/project1/project/gunicorn.sh                    ; Command to start appuser = root                                                     ; User to run asstdout_logfile = /var/log/gunicorn_supervisor.log   ; Where to write log messagesredirect_stderr = true                                                ; Save stderr in the same logenvironment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8                       ; Set UTF-8 as default encoding
啟動
supervisord -c  supervisord.conf
管理
supervisorctl -c supervisord.conf

參考:https://docs.gunicorn.org/en/latest/deploy.html

參考:http://supervisord.org/

6
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 小程式雲開發入門第五章,雲資料庫的講解