Answer the question
In order to leave comments, you need to log in
How to set up Nginx-Tornado-Websocket binding?
Help setting up Nginx-Tornado-Websocket.
Through Nginx, it turns out to load only statics, there is no switching to Websocket.
Standalone (without Nginx) the Tornado application works fine on port 9001 with these settings.
Handlers:define("port", default=9001)
handlers = [
(r"/", MainHandler),
(r"/botsocket", BotSocketHandler),
]
var url = "ws://IP_сервера/botsocket";
worker_processes 2;
#user root;
user nginx;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
upstream websocket {
server IP_сервера:9001;
#server 127.0.0.1:9001;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
keepalive_timeout 86400;
proxy_connect_timeout 86400;
proxy_send_timeout 86400;
proxy_read_timeout 86400;
server {
listen 80;
location ^~ /static/ {
root /var/www/python/test/;
if ($query_string) {
expires max;
}
}
# WebSocket.
location /botsocket {
proxy_http_version 1.1;
#proxy_set_header Connection "upgrade";
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://websocket;
#proxy_pass http://websocket/botsocket;
#proxy_pass http://IP_сервера:9001/botsocket;
#proxy_pass http://127.0.0.1:9001/botsocket;
}
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://127.0.0.1:9001/;
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question