I'm using FastCGI to serve my Django app, so basically it works like this: http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/#running-djang开发者_Go百科o-on-a-shared-hosting-provider-with-apache
What is the best way I can serve static media (images, css, etc) from this? Thanks!
If using Apache to front the site we normally go with WSGI for connecting to django and then let Apache handle '/media/...anything...' as statically served content. It's a couple lines of config and Bob's your Uncle!
Update: I should add that most of our Django sites are on dedicated servers, but you also can do this easily at webfaction.com.
E.g.
<Location "/media">
SetHandler None
</Location>
Add any appropriate Alias
directives to your web server configuration, from deepest to shallowest.
I use this in my apache conf:
Alias /static/ /path/to/static/files/
<Directory /path/to/static/files/>
Order deny,allow
Allow from all
</Directory>
If you don't have write access to your apache conf, you can do this in your .htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/path/to/media/files/
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]
Or something similar. This ensures that any urls beginning with the path to your media files do not redirect to fast cgi. If you already have some conditions you can add multiple RewriteCond
s using [OR]
.
精彩评论