Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
litespeed_wiki:python_fcgi [2007/08/03 14:23]
127.0.0.1 external edit
— (current)
Line 1: Line 1:
-====== Python FastCGI Application and LiteSpeed ====== 
  
-This is a generic FCGI how-to for Python applications. Although we use Jon's fcgi python library for this example, you can use any valid Python FCGI module for your own setup. 
- 
-Live Demo: http://​www.litespeedtech.com/​products/​webserver/​demo/​ 
- 
-===== Requirements ===== 
- 
-  - LiteSpeed 
-  - Python 
-  - Jon's Python FCGI library: [[http://​jonpy.sourceforge.net/​|jonpy.sourceforge.net]] 
- 
- 
-===== Setup ===== 
- 
-1) Create a Virtual Host for this setup. From now on we will refer to this vhost as PythonVhost. 
- 
-2) Save the following sample Python FCGI application to a path of your choice. We will call this app "​demoapp.py"​ for tutorial purposes. 
- 
-<​code>​ 
-#​!/​usr/​bin/​python 
-import jon.cgi as cgi 
-import jon.fcgi as fcgi 
-from cgi import escape 
-import traceback 
- 
-class Handler(cgi.Handler):​ 
-  def process(self,​ req): 
-    req.set_header("​Content-Type",​ "​text/​html"​) 
-    req.write("​Hello Python! Hello LiteSpeed!<​hr size=1>"​) 
-    keys = req.environ.keys() 
-    keys.sort() 
-    for k in keys: 
-        req.write(escape(k) + " = " + escape(req.environ[k]) + "<​br>"​) 
-    req.write(traceback.print_exc()) 
- 
-fcgi.Server({fcgi.FCGI_RESPONDER:​ Handler}).run() 
-</​code>​ 
- 
-3) Go "​PythonVhost -> External Apps" tab and create a new "​External Application"​. 
- 
-<​code>​ 
-Name: MyPythonFCGI  
-Address: uds://​tmp/​lshttpd/​mypythonfcgi.sock 
-Max Connections:​ 10 
-Initial Request Timeout (secs): 10 
-Retry Timeout (secs): 0 
-Persistent Connection Yes 
-Connection Keepalive Timeout: 30 
-Response Bufferring: No  
-Auto Start: Yes 
-Command: /​absolutepathto/​demoapp.py ​ <--- path to python fcgi app 
-Back Log: 50 
-Instances: 10 
-</​code>​ 
- 
-4) Go to "​PythonVhost -> Contexts"​ and create a new "FCGI Context"​. 
- 
-<​code>​ 
-URI: /​python/ ​  <​--- URI path to bind to python fcgi app we created  
-Fast CGI App: [VHost Level] MyPythonFCGI ​ <--- select the python extapp we just created 
-</​code>​ 
- 
- 
-5) Restart LiteSpeed, "​lswsctrl restart",​ and access your new Pythyon FCGI application with /python/ url to your vhost. Enjoy! =) 
  • Admin
  • Last modified: 2015/07/29 14:45
  • (external edit)