在同一台服务器上运行Tornado和Nginx
问题描述:
我现在有一个由nginx提供服务的静态网站,并且我想在同一台服务器上使用Tornado开发一个应用程序.
I have a static website served up by nginx right now, and I want to develop an app with Tornado on the same server.
Tornado文档提到wsgi不支持非阻塞请求.
The Tornado documentation mentions that wsgi doesn't support non-blocking requests.
我是否有办法让他们(在同一台服务器上)一起工作?
Is there a way for me to get them to work together (on the same server)?
答
可以.看看龙卷风首页上的 nginx.conf示例.
Sure you can. Take a look at the 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;
}
...
}
...
}