Solved

python fastcgi nginx

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
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…

708 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

12 Experts available now in Live!

Get 1:1 Help Now