This repository has been archived by the owner on Oct 12, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
FastCGIWSGI
155 lines (112 loc) · 3.4 KB
/
FastCGIWSGI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
[[PageOutline]]
= FastCGI WSGI =
This is a HOWTO. See BehindApache for a higher-level discussion.
A very simple setup lets your cherry run with FastCGI (on apache in my setup). You need just a running apache server with mod_fastcgi and [http://www.saddi.com/software/flup/ flup].
== CherryPy code ==
hello.py:
{{{
#!python
#!/usr/bin/python
import cherrypy
class HelloWorld:
""" Sample request handler class. """
def index(self):
return "Hello world!"
index.exposed = True
cherrypy.tree.mount(HelloWorld())
# CherryPy autoreload must be disabled for the flup server to work
cherrypy.config.update({'engine.autoreload_on':False})
}}}
Then run the shiny new cherryd with the '-f' arg:
{{{
cherryd -c <myconfig> -d -f -i hello.py
}}}
== Apache config ==
At the top level in httpd.conf:
{{{
FastCgiIpcDir /tmp
FastCgiServer /path/to/cherry.fcgi -idle-timeout 120 -processes 4
}}}
And inside the relevant !VirtualHost section:
{{{
# FastCGI config
AddHandler fastcgi-script .fcgi
ScriptAliasMatch (.*$) /path/to/cherry.fcgi$1
}}}
== Lighttpd config ==
For [http://www.lighttpd.net/ Lighttpd] you can follow these instructions. Within `lighttpd.conf` make sure `"mod_fastcgi"` is active within `server.modules`. Then, within your `$HTTP["host"]` directive, configure your fastcgi script like the following:
{{{
$HTTP["url"] =~ "" {
fastcgi.server = (
"/" => (
"script.fcgi" => (
"bin-path" => "/path/to/your/script.fcgi",
"socket" => "/tmp/script.sock",
"check-local" => "disable",
"disable-time" => 1,
"min-procs" => 1,
"max-procs" => 1, # adjust as needed
),
),
)
} # end of $HTTP["url"] =~ "^/"
}}}
Please see [http://trac.lighttpd.net/trac/wiki/Docs:ModFastCGI] for an explanation of the possible configuration options.
{{{
#!html
<h2 class='compatibility'>Older versions</h2>
}}}
Use autoreload.on = False instead of engine.autoreload_on = False.
== 3.0 ==
{{{
#!python
#!/usr/bin/python
import cherrypy
from flup.server.fcgi import WSGIServer
class HelloWorld:
""" Sample request handler class. """
def index(self):
return "Hello world!"
index.exposed = True
app = cherrypy.tree.mount(HelloWorld())
cherrypy.engine.start(blocking=False)
try:
WSGIServer(app).run()
finally:
# This ensures that any left-over threads are stopped as well.
cherrypy.engine.stop()
}}}
== 2.2 ==
{{{
#!python
#!/usr/bin/python
import cherrypy
class HelloWorld:
""" Sample request handler class. """
def index(self):
return "Hello world!"
index.exposed = True
cherrypy.tree.mount(HelloWorld())
cherrypy.server.start(initOnly=True, serverClass=None)
# use flup to start wsgi server
from cherrypy._cpwsgi import wsgiApp
from flup.server.fcgi import WSGIServer
WSGIServer(wsgiApp).run()
}}}
== 2.0 ==
{{{
#!python
#!/usr/bin/python
from cherrypy import cpg
class HelloWorld:
""" Sample request handler class. """
def index(self):
return "Hello world!"
index.exposed = True
cpg.root = HelloWorld()
cpg.server.start(initOnly=True, serverClass=None)
# use flup to start wsgi server
from cherrypy._cpwsgi import wsgiApp
from flup.server.fcgi import WSGIServer
WSGIServer(wsgiApp).run()
}}}