0

After upgrade to jessie my django stops working. I found that problem is in mod_python, so I decided that this is good reason to migrate to mod_wsgi. I read this but i'm not sure what to do if i got more than one project:

I got few projects in /home folder:

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

my apache's http.conf (not migrated to 2.4 yet, so please ignore Order/allow etc)

<VirtualHost *:80>
  ServerAdmin [email protected]

  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>

I'm thinking about daemon mode, but how to use it on different projects???

Update According to @GrahamDumpleton's answer my new apache looks like:

ServerAdmin [email protected]

 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>

Now it works - Thanks

1 Answer 1

1

Since your projects are all at separate sub URLs, simply use multiple WSGIScriptAlias directives, one for each sub URL. And definitely use a daemon process group for each distinct Django instance.

For some additional reading see:

There are also the mod_wsgi docs, although they are in a slight mess right now.

Sign up to request clarification or add additional context in comments.

2 Comments

WSGIApplicationGroup ? Is it useless for me?
If using WSGIScriptAlias for everything and process-group option is always used with it, then yes, WSGIProcessGroup is not needed as the process-group option takes precedence for that WSGI application. BTW, since you have each in its own daemon process group, also add application-group=%{GLOBAL} to the WSGIScriptAlias at the end. This will ensure the use of main interpreter context of respective processes, which avoids problems with certain third party modules for Python which don't work in sub interpreters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.