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

migrating from mod_python into mod_wsgi (multiple projects)

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

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

我的 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 网站管理员@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>

现在可以使用了 - 谢谢

由于您的项目都在单独的子 URL 中,只需使用多个 WSGIScriptAlias 指令,每个子 URL 一个。并且绝对为每个不同的 Django 实例使用一个守护进程组。

有关更多阅读,请参阅:

还有 mod_wsgi 文档,尽管它们现在有点乱。