1

Sorry for the newbie apache question. I'm wondering if it's possible to set up the following non-conventional apache virtualhost (for a Django app):

-- If a file exists in the DocumentRoot (/var/www) it will be shown. So if /var/www/foo.html exists, then it can be seen at www.example.com/foo.html.

-- If file does not exist, it is served via a virtualhost. I'm using mod_wsgi with a WSGIScriptAlias directive that points to a Django app. So if there is no /var/www/bar.html, www.example.com/bar.html will be passed to the Django app, which may or may not be a 404 error.

One option is to create an Alias for each individual file/directory, but people want to be able to post a file without adding an alias, and we want to keep the above URL structure for legacy reasons.

Simplified Virtualhost is:

<VirtualHost *:80>
  ServerName www.example.com
  DocumentRoot /var/www

  WSGIScriptAlias / /path/to/django.wsgi
  <Directory /path/to/app>
    Order allow,deny
    Allow from all
  </Directory>

  Alias /hi.html /var/www/hi.html
</VirtualHost>

The goal is to have www.example.com/hi.html work as above, without the Alias line

Brett Thomas
  • 143
  • 3
  • Actually, figured it out! There's a great post on the mod_wsgi email list that explains how to do it: http://groups.google.com/group/modwsgi/browse_thread/thread/229840cff63e418b Make sure you read until the end, the first response has a couple bugs – Brett Thomas Nov 14 '11 at 18:05

2 Answers2

1

Documentation on mod_wsgi site on how to do this is at:

http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#The_Apache_Alias_Directive

Use combination of AddHandler and mod_rewrite. Don't use WSGIScriptAlias.

Graham Dumpleton
  • 6,090
  • 2
  • 21
  • 19
0

Using apache I do not believe this is possible, using nGinx however.

...
<The rest of your server {} config above>
location @fallback {
     proxy_pass http://<your_uwscgi_server>:<port>;
}
error_page 404 = @fallback;
<any futher server {} configuration>

I may be wrong, for instance I do not know enough about EnvIF in apache and ether this could be used to provide similar functionality.

Oneiroi
  • 2,063
  • 1
  • 15
  • 28
  • 2
    isn't [try_files](http://wiki.nginx.org/HttpCoreModule#try_files) intended for this? – Tobi Nov 14 '11 at 17:22
  • It is possible with Apache and is done all the time with PHP sites. How to do it with mod_wsgi is covered in mod_wsgi documentation. – Graham Dumpleton Nov 15 '11 at 00:24