running Tornado and Nginx on same server

后端 未结 1 2027
生来不讨喜
生来不讨喜 2021-02-03 11:13

I have a static website served up by nginx right now, and I want to develop an app with Tornado on the same server.

The Tornado documentation mentions that wsgi doesn\'t

相关标签:
1条回答
  • 2021-02-03 11:47

    Sure you can. Take a look at the nginx.conf example on tornado's homepage.

    The relevant bits in your case would be:

    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;
            }
            ...
        }
        ...
    }
    
    0 讨论(0)
提交回复
热议问题