2009/6/30 Paddy Joy <[email protected]>: > > Hi, > > I'm developing a website with a web designer who only uses basic html > (ms frontpage). > > For the dynamic part of the site I'm using django. > > I want to mount django at the root of the site but still allow the > designer to upload static files as they please. > > Reading the docs I have come up with the following configuration. Just > wondering if somebody who has done this type of setup before could > comment on my configuration. Is there anything I have missed or > anything I have overlooked with this config? > > Thanks, > Paddy > > <VirtualHost *:80> > > DocumentRoot /home/user/example.com/html > ServerName www.example.com > > ErrorLog /var/log/apache2/example.com.error.log > CustomLog /var/log/apache2/example.com.access.log combined > > > Alias /media /usr/lib/python2.5/site-packages/django/contrib/admin/ > media > Alias /static /var/django/example.com/static > > AliasMatch /(.*\.(html|htm|css|jpg|gif|png|pdf|doc|xls)) /home/user/ > example.com/html/$1 > > > <Directory /home/user/example.com/html> > allow from all > </Directory> > > > WSGIDaemonProcess example user=django group=django threads=25 > WSGIProcessGroup example > > WSGIScriptAlias / /var/django/example.com/django.wsgi > > </VirtualHost>
The preferred way of doing this is explained towards end of: http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive That is, to use: DocumentRoot /var/httpd/htdocs <Directory /var/httpd/htdocs> Options ExecCGI AddHandler wsgi-script .wsgi Order allow,deny Allow from all RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /django.wsgi/$1 [QSA,PT,L] </Directory> That is, all static files put under document root, with no need for any Alias directives of any sort. The Django application would then be stuck in that directory as django.wsgi file. The AddHandler directive is used to say the .wsgi file should be processed by mod_wsgi. What will happen is that the rewrite condition will be applied and if static file exists corresponding to the URL, it will be served as static file as per normal. If a static file doesn't exist, then the request is routed via the django.wsgi resource corresponding to your Django application. In the django.wsgi file, you will need to do a slight fixup to ensure that django.wsgi isn't used in URLs. As adapted from documentation, would use WSGI wrapper of: _application = django.core.handlers.wsgi.WSGIHandler() import posixpath def application(environ, start_response): # Wrapper to set SCRIPT_NAME to actual mount point. environ['SCRIPT_NAME'] = posixpath.dirname(environ['SCRIPT_NAME']) if environ['SCRIPT_NAME'] == '/': environ['SCRIPT_NAME'] = '' return _application(environ, start_response) The '_application' would be your normal Django application entry point. This approach is better as you don't have to change Apache configuration to add new static files types. You don't even need the Alias directive for mapping Django media directory so long as it also is under document root in required location. Whether this will work for you depends on whether you can trust the other developers as far as shared access to document root directory for sticking stuff. Graham --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "modwsgi" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/modwsgi?hl=en -~----------~----~----~----~------~----~------~--~---
