龙卷风代理whith nginx和子路径

时间:2017-05-11 13:29:21

标签: python redirect nginx proxy tornado

我想将请求从我的www.mydomain.com/subdirectory重定向到相应的Tornado服务器,如下所示:

www.example.com/app1 -> http://10.0.0.5:8082;
www.example.com/app2 -> http://10.0.0.6:8082;
www.example.com/app3 -> http://10.0.0.7:8082;

我有这个nginx配置:

location ^~ /app1 {
        proxy_pass http://10.0.0.5:8082/;
    }

location ^~ /app2 {
        proxy_pass http://10.0.0.6:8082/;
    }

location ^~ /app3 {
        proxy_pass http://10.0.0.7:8082/;
    }

我的龙卷风应用程序:

import tornado.ioloop
import tornado.web

class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.render("main.html")

class HomeHandler(tornado.web.RequestHandler):
    def get(self):
        self.render("home.html")

class UserHandler(tornado.web.RequestHandler):
    def get(self, user_id):
        self.render("user.html")

class UserStatusHandler(tornado.web.RequestHandler):
    def get(self, user_id):
        self.render("user_status.html")

def make_app():
    return tornado.web.Application([
        (r"/", MainHandler),
        (r"/home", HomeHandler),
        (r"/user/([0-9]*)", UserHandler),
        (r"/user/([0-9]*)/status", UserStatusHandler),
        '''
        my app have a lot of other pages with subpaths
        '''
    ])

if __name__ == "__main__":
    app = make_app()
    app.listen(8082)
    tornado.ioloop.IOLoop.current().start()

所以,当命中时:

http://www.example.com/app1 -> it works, main.html is rendered
http://www.example.com/app1/ -> Tornado throws an warning: WARNING:tornado.access:404 GET // (10.0.0.5) 0.41ms
http://www.example.com/app1/home -> Tornado throws an warning: WARNING:tornado.access:404 GET //home (10.0.0.5) 0.41ms
http://www.example.com/app1/home/ -> Tornado throws an warning: WARNING:tornado.access:404 GET //home/ (10.0.0.5) 0.41ms
http://www.example.com/app1/user/1 -> Tornado throws an warning: WARNING:tornado.access:404 GET //user/1 (10.0.0.5) 0.41ms
http://www.example.com/app1/user/1/status -> Tornado throws an warning: WARNING:tornado.access:404 GET //user/1/status (10.0.0.5) 0.41ms

该额外/在网址导致错误

那么请,有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

在我的位置添加/解决了问题。 谢谢Richard Smith。