-->

tornado Python: Tornado server integration with NG

2019-09-06 02:42发布

问题:

I am trying to run Tornado on multicore CPU with each tornado IOLoop process on a different core, and I'll use NGINX for proxy pass to Tornado processes. Now when I check http://www.tornadoweb.org/en/stable/guide/running.html

Editing the actual configuration here for more details:

events {
worker_connections  1024;
}

http {
upstream chatserver {
    server 127.0.0.1:8888;
  }

server {
    # Requires root access.
    listen       80;

    # WebSocket.
    location /chatsocket {
        proxy_pass http://chatserver;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    location / {
        proxy_pass http://chatserver;
    }
  }
}

Now previously I was able to connect to socket ws://localhost:8888 from client (When I was running python main.py but now I can't connect. At the server, NGINX is changing the request to http somehow that I want to avoid. Access logs at tornado server:

WARNING:tornado.access:400 GET /search_image (127.0.0.1) 0.83ms

How can I make the nginx only communicate via ws:// not http://

回答1:

I figured out the issue and it was solved by override tornado's check_origin function by making it return true in all cases. Thank you all.