【问题标题】:migrating from mod_python into mod_wsgi (multiple projects)从 mod_python 迁移到 mod_wsgi(多个项目)
【发布时间】:2015-09-03 19:12:15
【问题描述】:

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

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

  • /home/project1
  • /home/project2
  • /home/project3

我的 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>

现在可以了 - 谢谢

【问题讨论】:

    标签: django apache mod-wsgi mod-python


    【解决方案1】:

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

    更多阅读请参见:

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

    【讨论】:

    • WSGIApplicationGroup ?对我没用吗?
    • 如果对所有内容都使用WSGIScriptAlias 并且始终使用process-group 选项,那么是的,不需要WSGIProcessGroup,因为process-group 选项优先于该WSGI 应用程序。顺便说一句,由于您每个人都在自己的守护进程组中,因此还要在末尾添加application-group=%{GLOBAL}WSGIScriptAlias。这将确保使用各个进程的主解释器上下文,从而避免某些 Python 第三方模块在子解释器中不起作用的问题。
    猜你喜欢
    • 2010-10-13
    • 2012-12-19
    • 2015-04-05
    • 2011-01-26
    • 2020-08-14
    • 2010-12-09
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多