I've been replacing SVG images on my web site with SVGZ files, but I'm having trouble getting Pyramid to serve them from a static_url.
__init.py__
has:
config.add_static_view(name='static', path='app:static', cache_max_age=3600)
and the template has:
<img src="{{ 'app:static/img/file.svgz'|static_url }}" />
When the filename ends with .svg
Pyramid serves up the file, but when I replace it with .svgz
(yes, the SVGZ file is in the same directory with the same permissions as the SVG file), Pyramid doesn't respond to the URL and nginx reports a 404 (because the file isn't at /app/static/img/file.svgz
as far as nginx is concerned).
I have a sense this is because Pyramid doesn't know how to set the Content-Type / Content-Encoding for SVGZ so it hands it back to nginx, similar to this question about web fonts: Web fonts always return 404 from static path. Unfortunately, there's no answers in that posting, so I'm hoping someone out there knows how to configure Pyramid to serve up SVGZ (and other less usual types) statically.
Other similar questions (How to set the content type header in response for a particular file type in Pyramid web framework) mention that Pyramid uses the mimetypes
library to figure out file type information, but that library seems to grok svgz, so I don't know why it can't figure out how to serve up these files:
Python 3.4.2 (default, Oct 8 2014, 10:45:20)
[GCC 4.9.1] on linux
>>> import mimetypes
>>> mimetypes.guess_type('file.svgz')
('image/svg+xml', 'gzip')
FWIW, my Nginx config has the following, but I doubt this has much to do with what Pyramid is up to.
location ~ \.svgz$ {
add_header Content-Encoding gzip;
}
Edit: I think it is a misconfiguration of Nginx that's causing the problem, not anything to do with Pyramid. I'm using a proxy setup identical to what's in the Pyramid cookbook (http://docs.pylonsproject.org/projects/pyramid-cookbook/en/latest/deployment/nginx.html), including the static configuration shown in step 3, which states: "It's somewhat odd that the root doesn't point to the static directory, but it works because Nginx will append the actual URL to the specified path."
It looks to me as though there's some conflict between the location ~ \.svgz$
directive listed above and the static configuration for the Pyramid app. When I remove it, Nginx serves up the SVGZ file from my Pyramid static path, but it fails to set the proper content-encoding so it doesn't load in the browser. When I add the directive back in, Nginx reports a 404. It's as though the match on .svgz somehow short circuits appending the proper URL.