我想为本地主机连接使用一个资源层次结构,为所有其他连接使用另一个资源层次结构我该怎么办?
publicSite = Site(File("/var/www/"))
localhostSite = Site(File("/var/localhost/"))
publicServer = TCPServer(80, publicSite, interface="0.0.0.0")
localhostServer = TCPServer(80, localhostSite, interface="127.0.0.1")
似乎你不能同时听两个不同的接口。
我得到以下错误:
Traceback (most recent call last):
File "/usr/bin/twistd", line 21, in <module>
run()
File "/usr/lib/python2.5/site-packages/twisted/scripts/twistd.py", line 27, in run
app.run(runApp, ServerOptions)
File "/usr/lib/python2.5/site-packages/twisted/application/app.py", line 379, in run
runApp(config)
File "/usr/lib/python2.5/site-packages/twisted/scripts/twistd.py", line 23, in runApp
_SomeApplicationRunner(config).run()
File "/usr/lib/python2.5/site-packages/twisted/application/app.py", line 158, in run
self.postApplication()
File "/usr/lib/python2.5/site-packages/twisted/scripts/_twistd_unix.py", line 213, in postApplication
startApplication(self.config, self.application)
File "/usr/lib/python2.5/site-packages/twisted/scripts/_twistd_unix.py", line 174, in startApplication
service.IService(application).privilegedStartService()
File "/usr/lib/python2.5/site-packages/twisted/application/service.py", line 228, in privilegedStartService
service.privilegedStartService()
File "/usr/lib/python2.5/site-packages/twisted/application/internet.py", line 68, in privilegedStartService
self._port = self._getPort()
File "/usr/lib/python2.5/site-packages/twisted/application/internet.py", line 86, in _getPort
return getattr(reactor, 'listen'+self.method)(*self.args, **self.kwargs)
File "/usr/lib/python2.5/site-packages/twisted/internet/posixbase.py", line 467, in listenTCP
p.startListening()
File "/usr/lib/python2.5/site-packages/twisted/internet/tcp.py", line 733, in startListening
raise CannotListenError, (self.interface, self.port, le)
twisted.internet.error.CannotListenError: Couldn't listen on 127.0.0.1:80: (98, 'Address already in use').
1个
最佳答案
不要为第二台服务器绑定到0.0.0.0
,而是绑定到服务器上的一个或多个公共地址。Twisted不提供任何API来枚举主机上的地址,也不区分公共地址和私有地址(因为您的“公共”地址可能是10.x.x.x,而防火墙正在转发来自“实际”公共地址的通信)。
如果您需要发现您的地址而不是让它们由配置提供,那么在POSIX上,this ioctl example might help。
关于python - Twisted Python:如何为本地主机连接使用不同的资源层次结构?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/6064352/