Yesterday spent a whole day studying to build the nginx+python+fastcgi environment, and test no problem, because it is the first time, and refer to a lot of things online, there are a lot of online, but still take their own process record.
The main thanks to this brother's article to give me a lot of help http://blog.csdn.net/linvo/article/details/5870498, but this brother's test code I did not run successfully.
First, the environment configuration is mainly divided into the following steps :
1,Linux environment and Python environment (This step omitted)
2,nginx Environment, Flup, spawn-fcgi tools are deployed as follows
wget http://nginx.org/download/nginx-1.2.1.tar.gz
tar-xzvf nginx-1.2.1.tar.gz
cd nginx-1.2.1
./ Configure--prefix=/usr/local/nginx-1.2.1--with-http_stub_status_module--with-http_ssl_module--with-cc-opt= '- O2 ' make make
install
wget http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz
TAR-XZVF flup-1.0.2.tar.gz
cd flup-1.0.2
python setup.py install
http://www.lighttpd.net/download/ spawn-fcgi-1.6.3.tar.gz
TAR-XZVF spawn-fcgi-1.6.3.tar.gz
cd spawn-fcgi-1.6.3
./configure
Make make
install
default location in/usr/local/bin/spawn-fcgi
Second, configure nginx.conf support fastcgi
The configuration is unknown, the following is a virtual host configured. /NAIVELOAFER.CGI is the configuration of the fastcgi, request will be forwarded to the 5678-port program, configured to restart the Nginx service.
server {
listen ;
server_name naiveloafer.xxx.com;
Access_log logs/naiveloafer.xxx.com main;
Location/{
root/usr/local/nlweb/htdocs;
Index index.html index.htm;
}
location/naiveloafer.cgi {
Fastcgi_pass 127.0.0.1:5678;
Include fastcgi.conf;
}
}
Write the fcgi script and save it as fcgi.py:
#!/usr/bin/env python
#coding =utf-8
#author: Naiveloafer
#date: 2012-06-07
from flup.server.fcgi Import Wsgiserver
def naiveloafer_app (environ, start_response):
start_response (' OK ', [(' Content-type ', ' Text/plain ')]
Content = "Hello world!naiveloafer" return
[content]
if __name__ = = ' __main__ ':
wsgiserver ( Naiveloafer_app). Run ()
Open the monitor, specific parameters see the brother's article
Spawn-fcgi-f/usr/local/nlweb/cgi-bin/fcgi.py-a 127.0.0.1-p 5678-u nobody-f 5
At this point, the information can be returned from the fastcgi via the Web or HTTP request. But it's just a specific configuration.
How to handle the requested parameters, get the requested data to see