The Joyent Community

A place where the Joyent community can gather, help each other out, and stay informed.

You are not logged in.

  • Index
  •  » Django
  •  » Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

#1 2005-11-25 23:06:17

ubernostrum
My internets, let me show you them
From: Lawrence, KS
Registered: 2005-02-23
Posts: 2174
Website  Expertise

Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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.


When they lay you on the table, better keep your business clean.

Offline

 

#2 2005-11-25 23:50:39

ubernostrum
My internets, let me show you them
From: Lawrence, KS
Registered: 2005-02-23
Posts: 2174
Website  Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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.


When they lay you on the table, better keep your business clean.

Offline

 

#3 2005-11-26 00:34:32

pkit
Member
From: Dublin
Registered: 2005-11-07
Posts: 87
Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

Thank you so so so much! You've just made my day...

Offline

 

#4 2005-11-26 01:02:48

leftwing
Member
From: San Diego, CA
Registered: 2005-09-07
Posts: 57
Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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

 

#5 2005-11-26 02:09:44

electrospeck
Bidwellian
From: San Francisco
Registered: 2005-02-09
Posts: 1792
Website  Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

Nice smackdown, uber.


What premium smells like.
speck.me
Olie LOL

Offline

 

#6 2005-11-26 02:18:35

ubernostrum
My internets, let me show you them
From: Lawrence, KS
Registered: 2005-02-23
Posts: 2174
Website  Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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.


When they lay you on the table, better keep your business clean.

Offline

 

#7 2005-11-26 05:34:54

ubernostrum
My internets, let me show you them
From: Lawrence, KS
Registered: 2005-02-23
Posts: 2174
Website  Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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.


When they lay you on the table, better keep your business clean.

Offline

 

#8 2005-11-28 21:15:31

pkit
Member
From: Dublin
Registered: 2005-11-07
Posts: 87
Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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

 

#9 2005-11-28 22:10:58

ubernostrum
My internets, let me show you them
From: Lawrence, KS
Registered: 2005-02-23
Posts: 2174
Website  Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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.


When they lay you on the table, better keep your business clean.

Offline

 

#10 2005-11-28 23:03:09

pkit
Member
From: Dublin
Registered: 2005-11-07
Posts: 87
Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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

 

#11 2005-11-28 23:34:30

ubernostrum
My internets, let me show you them
From: Lawrence, KS
Registered: 2005-02-23
Posts: 2174
Website  Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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.


When they lay you on the table, better keep your business clean.

Offline

 

#12 2005-11-29 11:25:49

pkit
Member
From: Dublin
Registered: 2005-11-07
Posts: 87
Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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

 

#13 2005-11-29 11:31:02

pkit
Member
From: Dublin
Registered: 2005-11-07
Posts: 87
Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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

 

#14 2005-11-29 11:58:10

ubernostrum
My internets, let me show you them
From: Lawrence, KS
Registered: 2005-02-23
Posts: 2174
Website  Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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).


When they lay you on the table, better keep your business clean.

Offline

 

#15 2005-11-29 12:24:48

pkit
Member
From: Dublin
Registered: 2005-11-07
Posts: 87
Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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

 

#16 2005-11-29 12:46:58

ubernostrum
My internets, let me show you them
From: Lawrence, KS
Registered: 2005-02-23
Posts: 2174
Website  Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

Just added the bit about symlinking, as part of a slightly larger section on creating a 'media' directory and configuring Django to use it.


When they lay you on the table, better keep your business clean.

Offline

 

#17 2005-11-29 13:28:32

pkit
Member
From: Dublin
Registered: 2005-11-07
Posts: 87
Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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

 

#18 2005-11-29 16:34:40

Derek
Member
From: Washington, DC
Registered: 2005-02-23
Posts: 35
Website  Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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

 

#19 2005-11-29 18:49:00

ubernostrum
My internets, let me show you them
From: Lawrence, KS
Registered: 2005-02-23
Posts: 2174
Website  Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

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.


When they lay you on the table, better keep your business clean.

Offline

 

#20 2006-02-14 17:18:31

Dobbes
New member
Registered: 2006-02-14
Posts: 3
Expertise

Re: Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

thanks ubernostrum! the guide was a big help.

Offline

 
  • Index
  •  » Django
  •  » Django/lighttpd/FastCGI instructions now on manuals.textdrive.com

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson