2017年1月24日 星期二

一台伺服器、兩個 Django 項目

最近開發的 Django 項目是利用 Apache + mod_wsgi 來連接。它的設定像是:
<Virtualhost *:443>
   ServerAdmin server@pacess.com
   ServerName sita.pacess.com:443
   DocumentRoot /home/www/sita.pacess.com

   SSLEngine on
   SSLProtocol all -SSLv2 -SSLv3
   SSLCipherSuite ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA;
   SSLCertificateKeyFile /home/www/sita.pacess.com/ssl/domain.key
   SSLCertificateFile /home/www/sita.pacess.com/ssl/2017a/domain.crt
   SSLCertificateChainFile /home/www/sita.pacess.com/ssl/2017a/intermediate.pem
   SSLHonorCipherOrder on

   WSGIDaemonProcess sita python-path=/usr/lib/python3.5/site-packages
   WSGIProcessGroup sita
   WSGIScriptAlias / /home/www/sita.pacess.com/sita/wsgi.py

   Alias /django-static/ /home/www/sita.pacess.com/sita/static/
   <Directory /home/www/sita.pacess.com/sita/static>
      AllowOverride All
      Order Allow,Deny
      Allow from All
   </Directory>

   <Directory /home/www/sita.pacess.com/sita>
      <Files wsgi.py>
         Order Allow,Deny
         Allow from All
      </Files>
   </Directory>
</VirtualHost>

Django 需要一個 Process 名去綁定一個目錄。所以,要在同一台伺服器運行兩個 Django 項目,就要在 Apache 設定檔中加多一個 Process 名,如:
   WSGIDaemonProcess pacess python-path=/usr/lib/python3.5/site-packages
   WSGIProcessGroup pacess
   WSGIScriptAlias /pacess/ /home/www/sita.pacess.com/pacess/wsgi.py

沒有留言: