A place where the Joyent community can gather, help each other out, and stay informed.
You are not logged in.
A step-by-step set of instructions for setting up a Django project to run under lighttpd and FastCGI on TXD is now online:
http://manuals.textdrive.com/read/book/15
Suggestions and corrections are welcome; if you run into problems from following these instructions, let me know and I'll do my best to help you figure things out.
Offline
And, since it came up both for me and someone else, do please remember that things will break if you try to use CommonMiddleware while you have DEBUG = True in your settings. Changing it to False will clear it right up.
Offline
Awesome, you rock man. I'll have to dig into this when I get some free time. I took a quick breeze though it and was excited by how few steps there are. Thanks so much for putting this together.
Offline
Nice smackdown, uber.
Offline
More info on the CommonMiddleware thing: David (da) has done some more fiddling with it, and is finding that somehow request.path is coming up as an empty string. Not sure if that's a bug in the middleware or in how we're setting up Django/FCGI, though.
Offline
OK, got David's problem licked.
Anybody who's already tried to set up from the instructions above, you need to make a change to your lighttpd.conf. Unfortunately, Textile royally screws up the code, so it's snippeted here.
If you leave in that extra slash, the pattern doesn't match requests with no trailing slash, which means lighttpd falls back to the 404 handler. And for some reason lighttpd doesn't seem to pass PATH_INFO in that case, which means that if the 404 handler is Django's main.fcgi there's nothing for CommonMiddleware to work with and you'll get an exception thrown when it tries to append a slash to the end of the requested URL.
Offline
There is a major problem with the url matching regex in the sample lighttpd.conf:
url.rewrite = (
"(/[media].*)$" => "/main.fcgi$1"(note: it should read [^media] but the forum keeps messing the code up)
The part [^media] does not mean "not matching the word 'media'", it means not matching a 'm', 'e', 'd', 'i', or an 'a'. It should read as follows:
url.rewrite = (
"^(/(?!media).*)$" => "/main.fcgi$1"You need to use the negative look-ahead (?!media) to match the whole word.
Last edited by pkit (2005-11-28 21:18:55)
Offline
Thanks for that, regex-fu is not my strong point, and I suspected there was somethign wrong with that but never came back to give it a second look.
Just uploaded a new sample lighttpd.conf.
Offline
One more thing:
You should mention that the '/media/' path that the lighttpd config file deliberately doesn't pass on to the FCGI server is located in the standard document root, i.e. ~/web/public/ or ~/web/public_html/, so that any references to files in http://media.yourdomain.com or http://yourdomain.com/media will be served directly (i.e. these are the paths to store and reference css and image files from). So another page on creating a 'media' directory in the web root also mentioning the relevant settings in the django project settings file would be great; not to mention that if users want to use the standard admin interface they should copy the contents of ~/local/Django-0.90/django/contrib/admin/media (or whatever your Django path is) to ~/web/public/media
Offline
I'm actually thinking of recommending a 'media' directory, and then using ln to create a link inside it to the admin media directory, so that you don't have to keep copying over the directory every time you upgrade Django.
Offline
My current solution is to create a 'media' directory in the web root and to create an 'admin' directory inside it, which is a symlink to the admin media files in the django source so I can still upgrade django and not have to copy new files over but it also means that my media direcotry, which I use for all my django apps, isn't messed up with admin stuff. I then just update my project settings file so that my admin media path is '/media/admin/' and its done.
Offline
ubernostrum wrote:
Thanks for that, regex-fu is not my strong point, and I suspected there was somethign wrong with that but never came back to give it a second look.
Just uploaded a new sample lighttpd.conf.
Regex in sample conf seems to be totally different now:
^(/admin.*)$" => "/main.fcgi$1"
which will only match http://domain.com/admin/...
With this config no media files can be served directly from the same domain.
Offline
pkit wrote:
Regex in sample conf seems to be totally different now:
^(/admin.*)$" => "/main.fcgi$1"
which will only match http://domain.com/admin/...
With this config no media files can be served directly from the same domain.
I decided to change it so that, "out of the box", it would only handle the Django admin application, and updated the instructions to reflect this, with a notice that developers will need to construct rewrite rules tailored to their own application.
And media files can be served from the same domain; previously, the config attempted to route all requests to Django except those for files in the 'media' directory. Now it only routes requests to Django when they match a specified pattern. Which means that any request not passed to Django based on a matching pattern will be served by lighttpd as normal (although Django's main.fcgi is still the 404 handler).
Offline
ubernostrum wrote:
pkit wrote:
Regex in sample conf seems to be totally different now:
^(/admin.*)$" => "/main.fcgi$1"
which will only match http://domain.com/admin/...
With this config no media files can be served directly from the same domain.
I decided to change it so that, "out of the box", it would only handle the Django admin application, and updated the instructions to reflect this, with a notice that developers will need to construct rewrite rules tailored to their own application.And media files can be served from the same domain; previously, the config attempted to route all requests to Django except those for files in the 'media' directory. Now it only routes requests to Django when they match a specified pattern. Which means that any request not passed to Django based on a matching pattern will be served by lighttpd as normal (although Django's main.fcgi is still the 404 handler).
Fair enough, as long as the book still includes instructions about symlinking the admin media files - as the admin app is such an important part of Django and really doesn't work without the media files. I do agree about a 'match this' not 'match everything but this' approach.
Last edited by pkit (2005-11-29 12:28:10)
Offline
Just added the bit about symlinking, as part of a slightly larger section on creating a 'media' directory and configuring Django to use it.
Offline
Just read the new media section which is very clear. This how-to should be well advertised because its the most useful one I've read for setting up Django so far.
p.s. it's already been linked in the Django wiki
Offline
Thanks for this guide - installing django and the rest were easy. I ran into one snag, however; I'm using OS X and thus the tcsh shell, and setting the path and pythonpath using the instructions didn't work for me. I'm going to do some digging to try and figure out what the difference/issue is, but if anyone else knows, feel free to jump in. Thanks.
Offline
Derek, in tcsh you'd want to change a line like this:
export PATH=$PATH:/home/username/local/django_src/django/bin
To this:
setenv PATH "$PATH:/home/username/local/django_src/django/bin"
And put it in your .tcshrc file.
I'm not a tcsh expert by any means, but I'm pretty certain that's how it handles environment variables.
Offline