【问题标题】:Relative redirection in Python tornadoPython龙卷风中的相对重定向
【发布时间】:2020-02-26 13:32:05
【问题描述】:

我有一个 Tornado 网络应用程序,可以将用户重定向回主页(应用程序的“/”)。然后tornado web 应用程序使用 nginx 作为应用程序之一部署(例如 www.helloworld.com/app),重定向不再有效。下表应描述这种情况。

+-----------------------------+---------------------------------+
| Root URL of tornado app     | www.helloworld.com/app          |
| Redirect URL                | www.helloworld.com/app/redirect |
| Expected URL after redirect | www.helloworld.com/app          |
| Actual URL after redirect   | www.helloworld.com              |
+-----------------------------+---------------------------------+

这是我的重定向处理程序

class RedirectHandler(tornado.web.RequestHandler):
    def get(self):
        self.redirect(self.reverse_url("index"))

这是我的应用程序

handlers = [
            tornado.web.url(r'/', IndexPageHandler, name='index'),
            tornado.web.url(r'/redirect', RedirectHandler, name='redirect'),
        ]

【问题讨论】:

  • 当你实际重定向到/时,为什么你期望登陆/app
  • 其实应用是由 nginx 部署在 www.helloworld.com/app 的。但是tornado应用本身并不知道应用的位置。

标签: python nginx tornado


【解决方案1】:

Tornado 不适用于去除 URL 前缀的代理。使用完整的 URL (tornado.web.url(r'/app', IndexPageHandler, name='index')) 配置 Tornado 服务器,并从 nginx proxy_pass 指令中删除路径。

【讨论】:

  • 感谢您的信息。我理解您的观点,但服务器所有者和应用程序开发人员属于两个团队。如果龙卷风无法做到这一点,还有其他选择吗?我会活着听到更多:)
  • 我不知道;我从来没有参与过有这个要求的项目。如果 nginx 删除了/app/,它应该负责将其添加回来。看起来有一个proxy_redirect 选项。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-19
相关资源
最近更新 更多