Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
Actually, figured it out! There's a great post on the mod_wsgi email list that explains how to do it: groups.google.com/group/modwsgi/browse_thread/thread/… Make sure you read until the end, the first response has a couple bugs –  Brett Thomas Nov 14 '11 at 18:05
add comment

2 Answers

up vote 0 down vote accepted

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.

share|improve this answer
    
Yup, that's it. (For others curious, the thread I posted above was also helpful.) You guys are awesome. –  Brett Thomas Nov 22 '11 at 17:09
add comment

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.

share|improve this answer
2  
isn't 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 0:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.