How to make Nginx provide prepackaged content?

8

I've already enabled the HttpGzipStaticModule module and set the

gzip_static on;

But in response headers of a GET request does not appear

Content-Encoding    gzip
    
asked by anonymous 12.12.2013 / 03:44

2 answers

8

Look, I think you confused the module. HttpGzipStaticModule serves precompiled files if they exist. That is, if you have image.png and image.png.gz and the client asks image.png , the module will serve image.png.gz in place. Who does the compression is you.

To compress on time, use the NginxHttpGzipModule . Note, however, that by default it compresses only text/html . Pay attention to the parameters of this module to configure it right.

Another thing: images are already prepackaged in their vast majority (and in all cases you've cited). Trying to compress them will be useless. There are some tools that can help, such as OptiPNG (see this article with a list). Google also has tips about . But activating gzip will be useless.

    
12.12.2013 / 05:12
1

Well, I compact the files as soon as I upload the site updates and run this script that generates the * .gz that NGINX fetches.

#! /bin/bash

FILETYPES=( "*.woff" "*.css" "*.jpg" "*.jpeg" "*.gif" "*.png" "*.js"  )
# specify a list of directories to check recursively
DIRECTORIES="/www/siteX/static/"

for currentdir in $DIRECTORIES
do
   for i in "${FILETYPES[@]}"
   do
      find $currentdir -iname "$i" -exec bash -c 'PLAINFILE={};GZIPPEDFILE={}.gz; \
         if [ -e $GZIPPEDFILE ]; \
         then   if [ 'stat --printf=%Y $PLAINFILE' -gt 'stat --printf=%Y $GZIPPEDFILE' ]; \
                then    echo "$GZIPPEDFILE antigo, atualizando"; \
                        gzip -9 -f -c $PLAINFILE > $GZIPPEDFILE; \
                 fi; \
         else echo "$GZIPPEDFILE estah faltando, criando..."; \
              gzip -9 -c $PLAINFILE > $GZIPPEDFILE; \
         fi' \;
  done
done
    
12.12.2013 / 19:33