从mod_python迁移到mod_wsgi(多个项目)

时间:2015-09-03 19:12:15

标签: django apache mod-wsgi mod-python

升级到jessie后,我的django停止工作。我发现问题出在mod_python中,所以我认为这是迁移到mod_wsgi的好理由。 我读了this,但如果我有多个项目,我不知道该怎么办:

我在/ home文件夹中有几个项目:

  • / home / project1
  • /家庭/项目2
  • /家庭/项目3

我的apache的http.conf(尚未迁移到2.4,所以请忽略Order / allow等)

<VirtualHost *:80>
  ServerAdmin webmaster@mydomain.com

  DocumentRoot /var/www
  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>
  <Directory /var/www/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>
      <Location "/project1">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE project1.settings
        PythonInterpreter project1
        PythonOption django.root /project1
        PythonDebug On
        PythonPath "['/home', '/home/project1'] + sys.path"
      </Location>
      <Location "/project2">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE project2.settings
        PythonInterpreter project2
        PythonOption django.root /project2
        PythonDebug On
        PythonPath "['/home', '/home/project2'] + sys.path"
      </Location>
      <Location "/project3">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE project3.settings
        PythonInterpreter project3
        PythonOption django.root /project3
        PythonDebug On
        PythonPath "['/home', '/home/project3'] + sys.path"
      </Location>


      Alias /admin_media/ /usr/share/pyshared/django/contrib/admin/media/
      Alias /static/ /home/common/

      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
      <Directory "/usr/lib/cgi-bin">
        AllowOverride None
         Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log

  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn

  CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>

我正在考虑守护进程模式,但是如何在不同的项目中使用它?

更新 根据@ GrahamDumpleton的回答,我的新apache看起来像:

     ServerAdmin webmaster@mydomain.com

 DocumentRoot /var/www
 <Directory />
   Options FollowSymLinks
   AllowOverride None
 </Directory>
 <Directory /var/www/>
   Options Indexes FollowSymLinks MultiViews
   AllowOverride None
   Require all granted
 </Directory>
 WSGIDaemonProcess project1
 WSGIDaemonProcess project2
 WSGIDaemonProcess project3


 WSGIScriptAlias /project1/ /home/project1/wsgi.py process-group=project1
 WSGIScriptAlias /project2/ /home/project2/wsgi.py process-group=project2
 WSGIScriptAlias /project3/ /home/project3/wsgi.py process-group=project3


 <Directory /home/*>
   Require all granted
 </Directory>

 Alias /admin_media/ /usr/share/pyshared/django/contrib/admin/media/
 Alias /static/ /home/common/

 ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
 <Directory "/usr/lib/cgi-bin">
   AllowOverride None
   Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
   Require all granted
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log

  # Possible values include: debug, info, notice, warn, error, crit,
  # alert, emerg.
  LogLevel warn

  CustomLog ${APACHE_LOG_DIR}/access.log combined

  Alias /doc/ "/usr/share/doc/"
  <Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
  </Directory>
</VirtualHost>

现在它有效 - 谢谢

1 个答案:

答案 0 :(得分:1)

由于您的项目都位于不同的子URL中,因此只需使用多个WSGIScriptAlias指令,每个子URL一个。并且明确地为每个不同的Django实例使用守护进程组。

如需进一步阅读,请参阅:

还有mod_wsgi文档,虽然它们现在处于轻微的混乱状态。