Python, django, nginx, fastcgi- How they work - index.fcgi

Python, django, nginx, fastcgi- How they work - index.fcgi

Postby ocpaul20 » Sun Apr 07, 2013 3:42 am

Hi,
I have posted this to devshed as well, but I guess no-one has any suggestions there. Hopefully you will be able to point me to further understanding of this area.

I have 2 questions and I would be most grateful for some help please.

I am having great problems with understanding how nginx loads up a django application using fastcgi.
I have a development server running nginx and fastcgi on a Debian squeeze system.

In my django project directory, there is an index.fcgi which I want to be loaded when I go to the local domain http://mydomain.lcl
I guess that the index.fcgi is a python program which gets loaded and interpreted by the fastcgi server which gets called by the nginx location block to handle the index.fcgi.

I assume there is some mechanism to get from the index.fcgi to the django application directory and on from there to running the application.

My first question is...
Where can I read up about this process please?

My second question is...
What can I place in the index.fcgi to basically display "Hello World" or "this is index.fcgi" so that I know everything is being routed correctly through nginx, fastcgi, and reaching the django project directory?

something like this, but this does not do it.
=========================

index.fcgi

Code: Select all
#!/usr/bin/python
#
# djangoblog/index.fcgi
from django.http import HttpResponse

HttpResponse("Hello, world. You're at the djangoblog index.fcgi")

=========================

I have also found this which works to a certain extent. and may
help others in their understanding of the process somehow.
When I point my fastcgi server to this python program, it displays
the plain text in the browser, but does not show any html when I
change the Content-Type: (see below)

Code: Select all
# enable debugging
import cgitb
cgitb.enable(True)

# this gives a 502 Bad Gateway error in nginx
print "Content-Type: text/html;charset=utf-8"
print "<html><head><title>my title</title><head>"
print "<body><p>This is the body of the page</p></body></html>"

# This works fine by displaying plain text in the browser
#print "Content-Type: text/plain;charset=utf-8"
#print
#print "Hello World! Hello Paul !!"


Thanks,
Paul
ocpaul20
 
Posts: 3
Joined: Sun Apr 07, 2013 2:48 am

Re: Python, django, nginx, fastcgi- How they work - index.fc

Postby ocpaul20 » Sun Apr 07, 2013 4:09 am

For the last issue above, it seems that I forgot that the page Content-Type: has to be the first statment which gets output to the browser. This would make sense of course since the browser has to know what kind of content it will be rendering.

so this works fine now and may help others looking for similar.
Code: Select all
print "Content-Type: text/html"
print
print "Hello World! Hello Paul !!"

print "<html><head><title>my title</title><head>"
print "<body><p><b>This</b> is the body of the page</p></body></html>"


However, I would still like to know how Django fires up and gets redirected from the index.fcgi to run the code in urls.py and beyond.
Thanks
Paul
ocpaul20
 
Posts: 3
Joined: Sun Apr 07, 2013 2:48 am


Return to Web Development

Who is online

Users browsing this forum: Crimson King and 2 guests