Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

python fastcgi nginx

Posted on 2011-03-12
3
586 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

808 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