请问各位, 服务器端用的tornado, 假如几个domain都指向了同一个地址, 应该怎么得到被访问的域名呢?
1
zjxubinbin 2015-08-08 20:00:15 +08:00
你想是问Tornado怎么实现Vhost吧,用Nginx就行了呀,不同的Hostname转发给不同的Tornado实例.
|
2
janxin 2015-08-08 22:04:28 +08:00 1
如果前面有nginx的话,设置
proxy_set_header Host $host; 然后tornado中: self.request.host可以取的到 |
3
spritevan 2015-08-09 00:50:49 +08:00
<https://github.com/tornadoweb/tornado/blob/master/tornado/web.py#L1705>
""" We support virtual hosts with the `add_handlers` method, which takes in a host regular expression as the first argument:: application.add_handlers(r"www\.myhost\.com", [ (r"/article/([0-9]+)", ArticleHandler), ]) """ |