views:

260

answers:

2

I have a httpd.conf file that looks like this:

Alias /robots.txt /var/www/tech_eval/static/robots.txt
Alias /favicon.ico /var/www/tech_eval/static/favicon.ico

AliasMatch /([^/]*\.css) /var/www/tech_eval/static/styles/$1

Alias /media/ /var/www/tech_eval/static/media/

<Directory /var/www/tech_eval/static>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias /tech_eval /var/www/tech_eval/scripts/django.wsgi

<Directory /var/www/tech_eval/scripts>
Order allow,deny
Allow from all
</Directory>

This works fine for my tech_eval project, but it's starting to cause problems with other sites. I think it might be appropriate me for to move all this stuff to a .htaccess file located in the tech_eval folder so that it doesn't cause problems. Although, I don't think all these options will work when ran from a .htaccess will they? What are my options? I mean, I could fix this by prefixing everything with tech_eval but then I'd wind up with one big master file for all my sites and it would just become a big mess.

+1  A: 

Use VirtualHosts to limit the scope of these lines, and an include per virtual host to organize your config files and keep it from growing unwieldy.

Matt Miller
Uhh...how's that work? I'm looking at this `<VirtualHost>` directive now... do I need multiple IP addresses...? I'm a complete n00b when it comes to this. I've installed `phppgadmin` recently, and it looks like the `Alias` for it is set in `/etc/apache2/conf.d`. Couldn't I just have a file like that for each of my sites? Are those loaded automatically??
Mark
Unfortunately, the way Apache config files are organized varies wildly by distribution. It's enough to make you go nuts sometimes. Look for Include lines in your httpd.conf file, probably near the bottom. If the path is a directory, it will include all the files in that directory.
Matt Miller
You don't need separate IP addresses for name-based virtual hosts (http://httpd.apache.org/docs/1.3/vhosts/name-based.html) You DO need separate domain names (or at least, subdomain names) -- which I'm assuming you have because of phrases like "all my sites."
Matt Miller
@Matt: Err..no, I don't have separate domain names for them. They're just in separate folders. Too cheap to buy domains for a school project :p
Mark
+1  A: 

It isn't actually too clear what problem you are trying to solve. Why are you even using that configuration in the first place? It looks like you just copied it from mod_wsgi documentation without understanding what each bit does and started using it when it isn't even appropriate for your setup. Specifically that example in mod_wsgi documentation was a generic example and not necessarily suited for Django.

So, rather that trying to fix that configuration to meet some unknown goal, just describe what you need and will tell you what the proper configuration is that you should be using.


UPDATE 1

Per my comment below, perhaps then use:

AliasMatch /tech_eval/([^/]*\.css) /var/www/tech_eval/static/styles/$1

Alias /tech_eval/media/ /var/www/tech_eval/static/media/

<Directory /var/www/tech_eval/static>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias /tech_eval /var/www/tech_eval/scripts/django.wsgi

<Directory /var/www/tech_eval/scripts>
Order allow,deny
Allow from all
</Directory>

Just ditch robots.txt and favicon.ico, or at least don't get them from sub URL site and just stick them direct in the DocumentRoot directory and use those which truly are for whole of site.

I think it is 'ADMIN_MEDIA_PREFIX' in Django settings module that you then need to change to '/tech_eval/media/'.

For Django don't think you even need to CSS alias and that is where this was originally a generic example to show concepts rather than be something which was correct for Django.

Anyway, everything is then under '/tech_eval' and shouldn't interfere with other applications on same site.

Graham Dumpleton
I didn't copy it from the mod_wsgi documentation, I copied it from the Django tut, and I know exactly what it does. I have a project called `tech_eval`; that configuration is specific to that project. I want to somehow encapsulate that configuration so that it doesn't affect my other projects (since `httpd.conf` is "global" in a sense). I think it would be most appropriately placed inside the actual project folder, but I'm open to other solutions.
Mark
The tutorial copied it from 'http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#Hosting_Of_Static_Files' then. My concern is that configuration is pushing stuff to root of site for something that is at a sub URL. Yes that is what the original example was doing, but do you really want that? Do what want favicon.ico and robots.txt to come from that specific sub URL site? Do you want CSS files to be pushed to root? Because Alias/AliasMatch take precedence over WSGIScriptAlias, you can prefix LHS with '/tech_eval'. Just change Django settings for media URL root.
Graham Dumpleton