我尝试使用他们网站上的示例来测试cherrypy框架:
import cherrypy
class HelloWorld(object):
def index(self):
return "Hello World!"
index.exposed = True
cherrypy.quickstart(HelloWorld())
当我运行它时,我在控制台中得到了这个响应:
[05/Dec/2011:00:15:11] ENGINE Listening for SIGHUP.
[05/Dec/2011:00:15:11] ENGINE Listening for SIGTERM.
[05/Dec/2011:00:15:11] ENGINE Listening for SIGUSR1.
[05/Dec/2011:00:15:11] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at '' has an empty config.
[05/Dec/2011:00:15:11] ENGINE Started monitor thread '_TimeoutMonitor'.
[05/Dec/2011:00:15:11] ENGINE Started monitor thread 'Autoreloader'.
[05/Dec/2011:00:15:12] ENGINE Serving on 127.0.0.1:8080
[05/Dec/2011:00:15:12] ENGINE Bus STARTED
在本地运行浏览器并指向localhost:8080时,它可以工作。如何配置应用程序以使其响应域名:www.example.com
?我希望在我的具有域名的生产服务器中测试Hello World
,以便世界上任何人都可以从任何位置或任何计算机访问它?
答案 0 :(得分:1)
您将使用静态IP作为生产服务器...
config = {
'global' : {
'server.socket_host' : 'XXX.XXX.XXX.XXX',
'server.socket_port' : 80,
}
}
cherrypy.quickstart(HelloWorld(), '/', config)
然后为您的域名提供dns条目,www.example.com,指向静态IP 希望这有帮助!