在同一台服务器上运行Tornado和Nginx

时间:2011-12-07 00:44:56

标签: web-applications nginx tornado

我现在有一个由nginx提供的静态网站,我想在同一台服务器上开发一个带有Tornado的应用程序。

Tornado文档提到wsgi不支持非阻塞请求。

有没有办法让他们一起工作(在同一台服务器上)?

1 个答案:

答案 0 :(得分:17)

当然可以。看看nginx.conf example on tornado's homepage

您案例中的相关位将是:

http {
    # Enumerate all the Tornado servers here
    upstream frontends {
        server 127.0.0.1:8000;
        server 127.0.0.1:8001;
        server 127.0.0.1:8002;
        server 127.0.0.1:8003;
    }
    ...
    server {
        ...
        # for your "static" website
        location ^~ /static/ {
            root /var/www;
            if ($query_string) {
                expires max;
            }
        }
        # for your tornado's app
        location / {
            proxy_pass_header Server;
            proxy_set_header Host $http_host;
            proxy_redirect false;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Scheme $scheme;
            proxy_pass http://frontends;
        }
        ...
    }
    ...
}
相关问题