3

在使用龙卷风时,我发现了 gzip=True 功能,该功能在从命令行运行应用程序时工作正常,设置如下:

define("port", default=settings.LISTEN_PORT, help="run on the given port", type=int)
define("debug", default=True, help="run in debug mode", type=bool)
define("dont_optimize_static_content", default=False,
       help="Don't combine static resources", type=bool)
define("dont_embed_static_url", default=False,
       help="Don't put embed the static URL in static_url()", type=bool)

tornado.options.parse_command_line()
tornado.options.options['log_file_prefix'].set('/var/log/tmp.log')

app_settings = dict(
    template_path=os.path.join(os.path.dirname(__file__), "templates"),
    static_path=os.path.join(os.path.dirname(__file__), "static"),
    xsrf_cookies=False,
    gzip=True,
    debug=True,
)

但是,使用来自 tornado 服务器的 supervisord/nginx 响应部署应用程序不会被压缩。

[program:app-8001]
command=python /var/app/server/app.py --port=8001 --logging=debug ----dont_optimize_static_content=False
directory=/var/app/server/
stderr_logfile = /var/log/app-stderr.log
stderr_logfile_backups=10
stdout_logfile = /var/log/app-stdout.log
stdout_logfile_backups=10
process_name=%(program_name)s
loglevel=debug

任何想法我做错了什么?

4

1 回答 1

1

默认情况下,nginx 在代理对 Tornado 的请求(或与此相关的任何内容)时不会执行 HTTP/1.1 请求。Tornado 需要 HTTP/1.1 支持才能返回 gzip'ed 内容。

来自 web.py 的重要代码片段

def __init__(self, request):
    self._gzipping = request.supports_http_1_1() and \
        "gzip" in request.headers.get("Accept-Encoding", "")

通过将以下内容添加到您的配置文件中应该可以覆盖它 - 但是它不适用于我的实例。

proxy_http_version 1.1;
于 2013-02-26T05:50:24.187 回答