如何在nginx上部署tornado页面?

2024-03-29 05:46:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在学习龙卷风并尝试在nginx上部署页面。在

我打开nginx.conf公司然后添加以下内容。。在

server{
                listen 80;
                server_name _;
                location / {
                        root /home/ubuntu/tornado;
                        index index.html;
                }
        }

然后我就可以看到那页。。。。在

但是,html上的tornado/python代码不会被执行。。。它只在页面上显示如下。。在

^{pr2}$

有什么我还没做的吗?谢谢你的帮助!在


Tags: namehomeindexserverubuntuconf部署html
1条回答
网友
1楼 · 发布于 2024-03-29 05:46:58

您应该将Nginx服务器配置为充当proxy
下面是一个最小的示例,它将提供Nginx的静态文件,并将充当tornado应用程序的代理。在

http {
    # Enumerate all the Tornado servers here
    upstream frontends {
        server 127.0.0.1:8000;
    }

    # ...

    server {
        listen 80;
        # ...

        location ^~ /static/ {
            # Path of your static files
            root /var/www;
        }

        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://frontends;
        }
    }
}

请注意,Tornado应用程序应该在端口8000上运行(除了nginx服务)。在

相关问题 更多 >