我在使用 mod_python 的 apache 后面部署cherrypy 时遇到问题。
我有这个 apache 配置:
4 <VirtualHost *>
5 ServerAdmin martin@podhola.com
6 ServerName pyth.madphoto.eu
7 DocumentRoot /development/webadmin-interface/
8 # Indexes + Directory Root.
9 <Location />
10 PythonPath "sys.path+['/development/webadmin-interface']"
11 SetHandler python-program
12 PythonHandler cherrypy._cpmodpy::handler
13 PythonOption cherrypy.setup main::start
14 PythonDebug On
15 </Location>
16
17 # Logfiles
18 ErrorLog /www/madphoto.eu/pyth/logs/error.log
19 CustomLog /www/madphoto.eu/pyth/logs/ccess.log combined
20 </VirtualHost>
这个cherrypy代码启动整个网站
#!/usr/bin/env python
2 # -*- coding: utf8 -*-
3
4 import os.path
5 import cherrypy
6 from mako.template import Template
7 from mako.lookup import TemplateLookup
8 from mako import exceptions
9 from mako.exceptions import RichTraceback
10 from ReadFromDB import *
11 from DeleteFromDB import *
12 from InsertToDB import *
13 from BasePage import BasePage
14 from ModifyEntryDB import *
15 #from cherrypy.process.plugins import Daemonizer
16 #from cherrypy import Application
17
18 current_dir = os.path.dirname(os.path.abspath(__file__))
19 mainlookup = TemplateLookup(directories=['./templates'], output_encoding='utf-8', input_encoding='utf-8', en coding_errors='replace', format_exceptions = True)
20
21 class Main(BasePage):
22 readfromdb = ReadFromDB()
23 deletefromdb = DeleteFromDB()
24 inserttodb = InsertToDB()
25 modifyentrydb = ModifyEntryDB()
26
27 def index(self):
28 try:
29 mIndextemplate = mainlookup.get_template("main_index.txt")
30 return mIndextemplate.render()
31 except:
32
33 traceback = RichTraceback()
34 for (filename, lineno, function, line) in traceback.traceback:
35 print "File %s, line %s, in %s" % (filename, lineno, function)
36 print line, "\n"
37 print "%s: %s" % (str(traceback.error.__class__.__name__), traceback.error)
38
39 index.exposed = True
40
41 #config = {
42 # '/bootstrap/css':{
43 # 'tools.staticdir.on': True,
44 # 'tools.staticdir.dir': os.path.abspath(os.path.join(os.path.dirname(__file__), 'static'))
45 # }
46 #}
47 def start():
48 cherrypy.tree.mount(Main(),config="/development/webadmin-interface/webadmin.conf")
49 cherrypy.engine.start()
50
51
52
53 #cherrypy.quickstart(Main(), "/", "webadmin.conf")
然后第一次刷新网站是做403禁止,第二次我进入apache错误日志
[21/May/2013:11:48:38] MOD_PYTHON Traceback (most recent call last):
File "/usr/lib/pymodules/python2.6/cherrypy/_cpmodpy.py", line 139, in handler
setup(req)
File "/usr/lib/pymodules/python2.6/cherrypy/_cpmodpy.py", line 84, in setup
func()
File "/development/webadmin-interface/main.py", line 49, in start
cherrypy.engine.start()
File "/usr/lib/pymodules/python2.6/cherrypy/process/wspbus.py", line 184, in start
self.publish('start')
File "/usr/lib/pymodules/python2.6/cherrypy/process/wspbus.py", line 147, in publish
output.append(listener(*args, **kwargs))
File "/usr/lib/pymodules/python2.6/cherrypy/_cpserver.py", line 90, in start
ServerAdapter.start(self)
File "/usr/lib/pymodules/python2.6/cherrypy/process/servers.py", line 53, in start
wait_for_free_port(*self.bind_addr)
File "/usr/lib/pymodules/python2.6/cherrypy/process/servers.py", line 251, in wait_for_free_port
raise IOError("Port %r not free on %r" % (port, host))
IOError: Port 8080 not free on '127.0.0.1'
但它不起作用,后面有很多手册(我尝试了不同的设置,但仍然不起作用)
我有 Debian 挤压服务器,cherrypy 3.1.2-1,apache2。
在cherrypy的独立启动内置服务器中,它可以完美运行。
请问你能帮忙吗?谢谢!