More articles on the Internet use Django, webpy, and other frameworks. Because I only use its CGI instead of pure web development, I do not plan to use such frameworks for the moment, directly use the flup package (in fact, most of the frameworks wsgi are also encapsulated flup ).
If you are not talking nonsense, go to the topic and check the required environment and tools:
1. linux2.6 (nonsense --!)
2. nginx (the FastCGI module must be included)
3. spawn-fcgi (Official download: http://redmine.lighttpd.net/projects/spawn-fcgi/wiki)
4. Python
5. flup (download: http://trac.saddi.com/flup)
Installation is a common method, so I will not discuss it one by one.
Just copy the FastCGI configuration of nginx to PhP.
First, draw a simple schematic diagram.
Spawn-fcgi is a tool used to enable multiple wsgiserver processes in FastCGI mode.
Example:
Spawn-fcgi-F/data/wsgiserver. py-A 127.0.0.1-P 5678-u www-F 5
-F determine the path of the wsgiserver script
-A FastCGI bound IP Address
-P FastCGI-bound Port
-What identity Does u run?
-F indicates the number of processes to be started (many people think it is-C, which is actually dedicated to PhP. Here we will use-f)
The part to be encoded is the wsgiserver. Here, we paste a simple test code.
#! /Usr/bin/ENV Python #-*-coding: UTF-8-*-import flup. server. fcgi as flupsdef application (Environ, start_response): "this function can be written as a module import" ret = "" try: uri = environ ['path _ info'] If Uri [-1] = "/": uri = URI [:-1] If uri = "": ret = STR (Environ) Elif uri = "/sleep": import time. sleep (5) ret = "sleep: 5 secends" else: ret = URI failed t exception, E: ret = STR (E) status = '200 OK 'response_headers = [('content-type', 'text/plain')] start_response (status, response_headers) return [RET] If _ name _ = "_ main _": # Run in Python # flups. wsgiserver (application, multithreaded = true, Multiprocess = false, bindaddress = ('2017. 0.0.1 ', 5678 )). run () # Run flups in FastCGI mode. wsgiserver (application ). run ()
Er, that's it ~