1 | #!/usr/bin/env python |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | |
---|
4 | """ |
---|
5 | scgihandler.py - handler for SCGI protocol |
---|
6 | |
---|
7 | Modified by Michele Comitini <michele.comitini@glisco.it> |
---|
8 | from fcgihandler.py to support SCGI |
---|
9 | |
---|
10 | fcgihandler has the following copyright: |
---|
11 | " This file is part of the web2py Web Framework |
---|
12 | Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu> |
---|
13 | License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html) |
---|
14 | " |
---|
15 | |
---|
16 | This is a handler for lighttpd+scgi |
---|
17 | This file has to be in the PYTHONPATH |
---|
18 | Put something like this in the lighttpd.conf file: |
---|
19 | |
---|
20 | server.document-root="/var/www/web2py/" |
---|
21 | # for >= linux-2.6 |
---|
22 | server.event-handler = "linux-sysepoll" |
---|
23 | |
---|
24 | url.rewrite-once = ( |
---|
25 | "^(/.+?/static/.+)$" => "/applications$1", |
---|
26 | "(^|/.*)$" => "/handler_web2py.scgi$1", |
---|
27 | ) |
---|
28 | scgi.server = ( "/handler_web2py.scgi" => |
---|
29 | ("handler_web2py" => |
---|
30 | ( "host" => "127.0.0.1", |
---|
31 | "port" => "4000", |
---|
32 | "check-local" => "disable", # don't forget to set "disable"! |
---|
33 | ) |
---|
34 | ) |
---|
35 | ) |
---|
36 | |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | """ |
---|
41 | |
---|
42 | LOGGING = False |
---|
43 | SOFTCRON = False |
---|
44 | |
---|
45 | import sys |
---|
46 | import os |
---|
47 | |
---|
48 | path = os.path.dirname(os.path.abspath(__file__)) |
---|
49 | os.chdir(path) |
---|
50 | |
---|
51 | if not os.path.isdir('applications'): |
---|
52 | raise RuntimeError('Running from the wrong folder') |
---|
53 | |
---|
54 | sys.path = [path] + [p for p in sys.path if not p == path] |
---|
55 | |
---|
56 | import gluon.main |
---|
57 | |
---|
58 | # uncomment one of the two imports below depending on the SCGIWSGI server installed |
---|
59 | #import paste.util.scgiserver as scgi |
---|
60 | from wsgitools.scgi.forkpool import SCGIServer |
---|
61 | from wsgitools.filters import WSGIFilterMiddleware, GzipWSGIFilter |
---|
62 | |
---|
63 | wsgiapp = WSGIFilterMiddleware(gluon.main.wsgibase, GzipWSGIFilter) |
---|
64 | |
---|
65 | if LOGGING: |
---|
66 | application = gluon.main.appfactory(wsgiapp=wsgiapp, |
---|
67 | logfilename='httpserver.log', |
---|
68 | profiler_dir=None) |
---|
69 | else: |
---|
70 | application = wsgiapp |
---|
71 | |
---|
72 | if SOFTCRON: |
---|
73 | from gluon.settings import global_settings |
---|
74 | global_settings.web2py_crontype = 'soft' |
---|
75 | |
---|
76 | # uncomment one of the two rows below depending on the SCGIWSGI server installed |
---|
77 | #scgi.serve_application(application, '', 4000).run() |
---|
78 | SCGIServer(application, port=4000).enable_sighandler().run() |
---|