[uWSGI] Flat file caching in subdirectories

Roberto De Ioris roberto at unbit.it
Wed Jul 13 08:40:34 CEST 2016



> On Tue, 12 Jul 2016 19:19:45 +0900
> Tim van der Linden <tim at shisaa.jp> wrote:
>
> Hi Roberto
>
> I have it in production now for testing and it seems to hold up well.
>
> One "bug" I noticed is the fact that headers get stripped. If uWSGI
serves the full request (does not pull it from cache) the headers look
fine:
>
> - Connection keep-alive
> - Content-Encoding gzip
> - Content-Type	text/html; charset=utf-8
> - Date Tue, 12 Jul 2016 12:57:54 GMT
> - Server nginx/1.6.2
> - Transfer-Encoding: chunked
> - Vary: Accept-Encoding
>
> However, if the same page gets cached and served via "static:" headers
get stripped:
>
> - Connection: keep-alive
> - Content-Length: 27301
> - Date: Tue, 12 Jul 2016 12:58:02 GMT
> - Last-Modified: Tue, 12 Jul 2016 11:11:09 GMT
> - Server nginx/1.6.2
>
> The Gzip header is gone and more importantly the "Content-Type" header
is gone which can cause issues in some browsers. This happens with this
route declaration:
>
> route-if = isfreshfile:/disk1/uwsgi_cache${PATH_INFO}file.html,2628000
static:/disk1/uwsgi_cache${PATH_INFO}file.html
>
> Can it be that there is a problem with "static:" in uWSGI? Or am I doing
something wrong in the "uwsgi-router-isfreshfile" plugin which strips
headers?
>
> For now I have set Nginx to force this header after uWSGI is finished ..

The static router tries to automatically detect the content type from the
file extension. If no extension is available, you'd better to use the
"file" router that allows key-values options:

file:filename=foobar,content_type=test/plain,...

Otherwise you can add headers manually:

route = ^/foo addehader:Hello: World

Regarding gzip, i strongly suggest you to generate 2 files, one plain and
one gzipped, using transformations chaining:

; store the original response
route = ^/foo tofile:foobar
; gzip it
route = ^/foo gzip:
; save it again with another name
route = ^/foo tofile:foobar.gz

then configure the file serving to use the .gz variant if possibile. This
is way faster and cheaper than gzipping on the fly:

http://uwsgi-docs.readthedocs.io/en/latest/StaticFiles.html#gzip-uwsgi-1-9

If you are using nginx for serving static files it already includes the
required module:

http://nginx.org/en/docs/http/ngx_http_gzip_static_module.html


-- 
Roberto De Ioris
http://unbit.com



-- 
Roberto De Ioris
http://unbit.com


More information about the uWSGI mailing list