Solved

python fastcgi nginx

Posted on 2011-03-12
3
560 Views
Last Modified: 2012-05-11
1) To start...do not give be a link to a page unless you have done this your self nad willing to walk though unclear explanations.
2) Experience with nginx and python

I want to use fastcgi with python

not Django
not web.py
not Turbo gears.

Just a simple good old fashion cgi that prints out "Hello World"

Must have experience with python and fastcgi. and use best practice.

Thanks





0
Comment
Question by:dmontgom
3 Comments
 
LVL 25

Accepted Solution

by:
clockwatcher earned 500 total points
ID: 35154016
Do you have a particular FastCGI python implementation in mind?  The newer python FastCGI implementations are WSGI compliant and expect a WSGI model app (http://www.python.org/dev/peps/pep-0333/).

Here's a barebones example nginx server config block which hands off any request coming in on port 80 to a fastcgi service running on localhost:9995.
server {
        listen 80;
        server_name  localhost;

        location / {
           fastcgi_pass localhost:9995;
           include fastcgi_params;

        }
    }

Open in new window


Here's an example of a FastCGI WSGI compliant HelloWorld app running on localhost:9995.  It uses flup to provide the FastCGI layer and WSGI compliant server.  If you have a different FastCGI implementation in mind, let us know which you want to use.
from flup.server.fcgi import WSGIServer
import cgi

def mycgi(environ, start_response):
    start_response('200 OK', [('Content-type', 'text/html')])
    form = cgi.FieldStorage( fp=environ["wsgi.input"], environ=environ)
    name = form.getfirst("name","World")
    out = "<html><body>Hello %s!</body></html>" % name
    return (out)

WSGIServer(mycgi, bindAddress=("127.0.0.1",9995)).run()

Open in new window

0
 
LVL 31

Expert Comment

by:James Murrell
ID: 36515796
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now