M
M
Max Payne2019-03-08 20:45:24
Nginx
Max Payne, 2019-03-08 20:45:24

Why doesn't unix socket (nginx + tornado) work?

I'm using ubuntu server 18.04, nginx and tornado
To launch a tornado I use the following code:

class Main:
    PORT_MASK = '111{}'
    PATH_MASK = '/tmp/111_{}'

    SETTINGS = {}

    ROUTE = []

    def __init__(self, use_unix_socket=False):
        server = tornado.httpserver.HTTPServer(tornado.web.Application(self.ROUTE, **self.SETTINGS))

        if use_unix_socket:
            server.add_socket(tornado.netutil.bind_unix_socket(self.PATH_MASK.format(0)))
        else:
            server.add_sockets(tornado.netutil.bind_sockets(int(self.PORT_MASK.format(0))))

        tornado.process.fork_processes(0)

        tornado.ioloop.IOLoop.current().start()

nginx config where i set up the server:
upstream 111 {
    server localhost:1110 fail_timeout=0;
    server unix:/tmp/111_0 fail_timeout=0;
}

(two lines just to show that the unix socket does not work, so I understand that there should be one)
And, in fact, if I run it with the use_unix_socket argument, nothing works for me, requests to the tornado do not go, nginx returns 502 error, if through a regular socket - everything is ok. What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max Payne, 2019-03-08
@YardalGedal

Solved by adding the mode argument to tornado.neturil.bind_unix_socket
Thanks Pavel Denisov , I wouldn’t have guessed that something was wrong with the rights.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question