当我们使用下面的 nginx 配置部署 tornado 应用后
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;
}
在 tornado.log 中请求ip全部都会显示成 127.0.0.1 ,类似下面这样[I 130125 21:44:54 web:1447] 200 GET / (127.0.0.1) 16.00ms
如何在 nginx 反向代理的情况下让 tornado.log 中的ip地址也能显示成真实的ip呢?
正确答案:除了 nginx 配置正确, 更重要的是需要在 tornado httpserver 中设置 xheaders=True
tornado.httpserver.HTTPServer(Application(), xheaders=True)
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
学习是最好的投资!