Opened 10 years ago

Closed 10 years ago

#718 closed defect (wontfix)

Simultaneous xslt and gzip_static yields error 500

Reported by: Forst Owned by:
Priority: minor Milestone:
Component: nginx-module Version: 1.7.x
Keywords: xslt, gzip_static Cc:
uname -a: Linux example.com 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.7.10
built by gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_xslt_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --with-ipv6

Description (last modified by Maxim Dounin)

Environment:
Path /foo/bar/ contains an XML-file foobar.xml, its compressed version foobar.xml.gz and a stylesheet foobar.xsl.

Configuration (simplified):

gzip_static on;
gzip_types text/plain text/xml;

location /foo/bar/test/ {
    alias /foo/bar/;
    index foobar.xml;
    xslt_stylesheet /foo/bar/feed.xsl;
    xslt_last_modified on;
}

Steps to reproduce:

  1. Navigate to http://example.com/foo/bar/test

Expected behavior:
Generated XHTML page is sent to the browser and displayed appropriately.

Actual result:
Error 500: Internal Server Error.
This appears in the error log:

[error] 31057#0: *1 libxml2 error: "Document is empty" while sending response to client
[error] 31057#0: *1 xmlParseChunk() failed, error:4 while sending response to client

Workaround:
Add gzip_static off; to location /foo/bar/test/.

However, this obviously disables the feature for all the files available through /foo/bar/test/. As the XML file is used as the index, I don't see an elegant way to disable gzip_static just for that file, as using location = /foo/bar/test/ will override all other options set in location /foo/bar/test/ and duplicating all options in both locations is undesirable.

Notes:
According to this topic: http://forum.nginx.org/read.php?21,120601,120601, the error is caused when libxml2 receives compressed input. It seems doubtful to me that current behavior (serving the precompressed file to libxml2) is correct.

Change History (2)

comment:1 by Forst, 10 years ago

Having feed.xsl precompressed does not cause the error to happen.

comment:2 by Maxim Dounin, 10 years ago

Description: modified (diff)
Resolution: wontfix
Status: newclosed

(Just a side note: in the example configuration provided there will be no problem, as gzip_static will not be enabled in location /foo/bar/test/. Additionally, it won't process XML files by default. I've changed the example to one actually affected.)

The problem here is that xslt filter knows nothing about previous request processing. In particular, it can't influence the decision of the gzip_static module to return compressed content. This is a limitation of the design used.

As a workaround, you can tell nginx to don't use gzip_static for XML files in the location with xslt filter enabled, either by disabling gzipping of text/xml in the location completely using the gzip_types directive:

location /foo/bar/test/ {
    gzip_types text/plain;
    ...
}

or by disabling gzip_static for index.xml files with and additional regexp-based location:

location /foo/bar/test/ {
    ...

    location ~ /index\.xml$ {
        gzip_static off;
    }
}

Hope this helps.

Note: See TracTickets for help on using tickets.