我在使用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>
和启动整个网站的这个樱桃代码
#!/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 squeeze服务器,cherrypy 3.1.2-1,apache2。
在cherrypy的独立启动内置服务器中,它运行良好。
请帮忙吗?谢谢!
答案 0 :(得分:0)
你正在启动cherrypy服务器和apache,start函数只会配置和挂载应用程序但不启动服务器,它应该如下所示:
def start():
cherrypy.tree.mount(Main(),
config="/development/webadmin-interface/webadmin.conf")
模块_cpmodpy
可以通过以下方式轻松阅读更多信息:
python -m pydoc cherrypy._cpmodpy
作为一般建议,你应该考虑使用mod_wsgi,mod_python是非维护的,并且被认为是不赞成使用mod_wsgi。