nginx gzip_static: why are the non-compressed files required?How do I serve pre-gzipped files with nginx so that they'll be shown as text in the browser?Help needed setting up nginx to serve static filesHelp me enable gzip compression on nginxWhy isn't the Nginx Gzip Precompression module working?Nginx gives 504 Gateway Time-out once moved to liveNginx and HttpGzipStaticModulegzip compression with nginx - Not being reported correctly in tests?How to set gzip_static and gzip_proxied in nginxGzip level for pre-compressed files?Nginx not sending gzipped assets when passing trough a load balancerNginx static files not being served

Do these creatures from the Tomb of Annihilation campaign speak Common?

Employee is self-centered and affects the team negatively

logo selection for poster presentation

Identity of a supposed anonymous referee revealed through "Description" of the report

Why did Ham the Chimp push levers?

Should one save up to purchase a house/condo or maximize their 401k first?

Why is the episode called "The Last of the Starks"?

Is it a good idea to copy a trader when investing?

What is the Ancient One's mistake?

mini sub panel?

Expl3 and recent xparse on overleaf: No expl3 loader detected

Why doesn't a particle exert force on itself?

The unknown and unexplained in science fiction

Was Mohammed the most popular first name for boys born in Berlin in 2018?

99 coins into the sacks

Do oversize pulley wheels increase derailleur capacity?

How to explain intravenous drug abuse to a 6-year-old?

Is the tensor product (of vector spaces) commutative?

Are wands in any sort of book going to be too much like Harry Potter?

When was it publicly revealed that a KH-11 spy satellite took pictures of the first Shuttle flight?

Names of the Six Tastes

Whose birthyears are canonically established in the MCU?

Illegal assignment from Id to List

What's an appropriate age to involve kids in life changing decisions?



nginx gzip_static: why are the non-compressed files required?


How do I serve pre-gzipped files with nginx so that they'll be shown as text in the browser?Help needed setting up nginx to serve static filesHelp me enable gzip compression on nginxWhy isn't the Nginx Gzip Precompression module working?Nginx gives 504 Gateway Time-out once moved to liveNginx and HttpGzipStaticModulegzip compression with nginx - Not being reported correctly in tests?How to set gzip_static and gzip_proxied in nginxGzip level for pre-compressed files?Nginx not sending gzipped assets when passing trough a load balancerNginx static files not being served






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















I'm working with nginx 1.4.4 running on Ubuntu 12.04.4.

nginx is reverse-proxing a cluster of Rails application servers.



Static files (mostly assets) are served directly, without hitting the application servers.

I've set it up to gzip responses and to use pre-compressed files when available.



http 
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
# other ngx_http_gzip_module directives...

server
# proxy configuration

location ^~ /assets/
gzip_static on;
expires max;
add_header Cache-Control public;
# root is inherited
try_files $uri =404;
error_page 404 /404.html;





This works.

I've tested it using a real pre-gzipped asset and a dummy non-compressed asset with the same name but different content:



/assets/application-a45d6...e2593.css # dummy content
/assets/application-a45d6...e2593.css.gz # real CSS


I could see that toggling gzip_static on and off would cause nginx to correctly serve the expected version of the file.

So far, so good.



However, this setup only works if the non-compressed version of the file is also present. Having only the pre-compressed version will cause a 404.



The documentation says:




gzip_static

With the “always” value (1.3.6), gzipped file is used in all cases, without checking if the client supports it. It is useful if there are no uncompressed files on the disk anyway or the ngx_http_gunzip_module is used.




(yes: I've tried both on and always, and I've also tried to add gunzip on. Nothing changed)



It seems to suggest that having only the compressed versions of the files is ok. Is this really the case? Is there anything wrong in my configuration?










share|improve this question




























    3















    I'm working with nginx 1.4.4 running on Ubuntu 12.04.4.

    nginx is reverse-proxing a cluster of Rails application servers.



    Static files (mostly assets) are served directly, without hitting the application servers.

    I've set it up to gzip responses and to use pre-compressed files when available.



    http 
    gzip on;
    gzip_http_version 1.0;
    gzip_proxied any;
    # other ngx_http_gzip_module directives...

    server
    # proxy configuration

    location ^~ /assets/
    gzip_static on;
    expires max;
    add_header Cache-Control public;
    # root is inherited
    try_files $uri =404;
    error_page 404 /404.html;





    This works.

    I've tested it using a real pre-gzipped asset and a dummy non-compressed asset with the same name but different content:



    /assets/application-a45d6...e2593.css # dummy content
    /assets/application-a45d6...e2593.css.gz # real CSS


    I could see that toggling gzip_static on and off would cause nginx to correctly serve the expected version of the file.

    So far, so good.



    However, this setup only works if the non-compressed version of the file is also present. Having only the pre-compressed version will cause a 404.



    The documentation says:




    gzip_static

    With the “always” value (1.3.6), gzipped file is used in all cases, without checking if the client supports it. It is useful if there are no uncompressed files on the disk anyway or the ngx_http_gunzip_module is used.




    (yes: I've tried both on and always, and I've also tried to add gunzip on. Nothing changed)



    It seems to suggest that having only the compressed versions of the files is ok. Is this really the case? Is there anything wrong in my configuration?










    share|improve this question
























      3












      3








      3


      1






      I'm working with nginx 1.4.4 running on Ubuntu 12.04.4.

      nginx is reverse-proxing a cluster of Rails application servers.



      Static files (mostly assets) are served directly, without hitting the application servers.

      I've set it up to gzip responses and to use pre-compressed files when available.



      http 
      gzip on;
      gzip_http_version 1.0;
      gzip_proxied any;
      # other ngx_http_gzip_module directives...

      server
      # proxy configuration

      location ^~ /assets/
      gzip_static on;
      expires max;
      add_header Cache-Control public;
      # root is inherited
      try_files $uri =404;
      error_page 404 /404.html;





      This works.

      I've tested it using a real pre-gzipped asset and a dummy non-compressed asset with the same name but different content:



      /assets/application-a45d6...e2593.css # dummy content
      /assets/application-a45d6...e2593.css.gz # real CSS


      I could see that toggling gzip_static on and off would cause nginx to correctly serve the expected version of the file.

      So far, so good.



      However, this setup only works if the non-compressed version of the file is also present. Having only the pre-compressed version will cause a 404.



      The documentation says:




      gzip_static

      With the “always” value (1.3.6), gzipped file is used in all cases, without checking if the client supports it. It is useful if there are no uncompressed files on the disk anyway or the ngx_http_gunzip_module is used.




      (yes: I've tried both on and always, and I've also tried to add gunzip on. Nothing changed)



      It seems to suggest that having only the compressed versions of the files is ok. Is this really the case? Is there anything wrong in my configuration?










      share|improve this question














      I'm working with nginx 1.4.4 running on Ubuntu 12.04.4.

      nginx is reverse-proxing a cluster of Rails application servers.



      Static files (mostly assets) are served directly, without hitting the application servers.

      I've set it up to gzip responses and to use pre-compressed files when available.



      http 
      gzip on;
      gzip_http_version 1.0;
      gzip_proxied any;
      # other ngx_http_gzip_module directives...

      server
      # proxy configuration

      location ^~ /assets/
      gzip_static on;
      expires max;
      add_header Cache-Control public;
      # root is inherited
      try_files $uri =404;
      error_page 404 /404.html;





      This works.

      I've tested it using a real pre-gzipped asset and a dummy non-compressed asset with the same name but different content:



      /assets/application-a45d6...e2593.css # dummy content
      /assets/application-a45d6...e2593.css.gz # real CSS


      I could see that toggling gzip_static on and off would cause nginx to correctly serve the expected version of the file.

      So far, so good.



      However, this setup only works if the non-compressed version of the file is also present. Having only the pre-compressed version will cause a 404.



      The documentation says:




      gzip_static

      With the “always” value (1.3.6), gzipped file is used in all cases, without checking if the client supports it. It is useful if there are no uncompressed files on the disk anyway or the ngx_http_gunzip_module is used.




      (yes: I've tried both on and always, and I've also tried to add gunzip on. Nothing changed)



      It seems to suggest that having only the compressed versions of the files is ok. Is this really the case? Is there anything wrong in my configuration?







      nginx gzip






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 3 '14 at 1:36









      tompavetompave

      2141312




      2141312




















          3 Answers
          3






          active

          oldest

          votes


















          4














          It's possible that you've found a bug. But in general you want both files anyway, for three reasons:



          1. A few clients won't request compressed data, and if you force it on them with gzip_static always; they might not understand it.

          2. To ensure that the file is always found, and the request isn't passed upstream to Rails or being caught by the 404 handler (the possible bug). One of which is probably what's happening.

          3. Having nginx compress or uncompress the file at runtime means it must do so repeatedly, eating up valuable CPU that could be used to run your application. It's much less CPU intensive to simply send a static resource.





          share|improve this answer

























          • Thanks. Yes, the request is being caught by the handler. I'm pretty sure because when I replaced the try_files directive with try_files $uri @named_proxy_loc; the request was sent to Rails.

            – tompave
            Feb 3 '14 at 2:15











          • Also, yes, I'm aware of the advantages, and I am indeed happy to have both versions of the assets on the server. I was just wondering if my configuration is ok or if I'm missing something.

            – tompave
            Feb 3 '14 at 2:15











          • As long as you have gzip_static on; and not always, and have both versions of the file, you should be fine.

            – Michael Hampton
            Feb 3 '14 at 2:16






          • 2





            try_files works before gzip_static therefore it looks for uncompressed file.

            – Alexey Ten
            Jul 11 '14 at 4:56


















          6














          Uncompressed files are not required on Nginx 1.6 with:



           location ~ .txt$ 
          gzip_static on;
          gunzip on;



          Both curl http://localhost/index.txt and curl -H "Accept-Encoding: gzip" http://localhost/index.txt | gunzip now work fine with just /srv/www/localhost/index.txt.gz in my root directory.






          share|improve this answer




















          • 4





            The gunzip directive is relatively new. And it had some bugs prior to the 1.6 stable release. Anyway, if you have the extra CPU to spend on it, go ahead, but it will almost always be faster to have the resource already (un)compressed and available to sendfile() immediately.

            – Michael Hampton
            Jul 10 '14 at 23:28












          • Have you benchmarked "it will almost always be faster". My own hunch is that it will be slower to have an uncompressed copy because, for a static HTTP server, CPU isn't traditionally the bottleneck compared to disk IO. As most clients will be using the compressed version, it is likely that it will already be cached. Even if it isn't, it's less data to read from the disk, so will be read quicker.

            – rjmunro
            Aug 23 '17 at 8:43






          • 1





            On Linux servers, the most accessed/recent files are cached on RAM thus, when doing benchmarks, after the first request, the subsequent ones will also be reading the file's content from RAM. So, my conclusion is that having both compressed and uncompressed is the optimal option, as no CPU time is involved and, practically, no slow disk I/O for the great majority of the requests (+99.999%).

            – Paulo Coghi
            Aug 23 '18 at 16:00



















          0














          Contrary to what @hendry says, I need to keep original files.



          I use nginx 1.15.9 (Ubuntu).



          gzip_static is compiled in:



          nginx -V 2>&1 | grep "--with-http_gzip_static_module



          gunzip is compiled in:



          nginx -V 2>&1 | grep "--with-http_gunzip_module".



          I have found this, though it may be outdated:




          try_files is not aware of gzip_static; but nginx will still
          honour it if both the non-gz and .gz files exist. This differs from
          the "normal" gzip_static handling which will serve the .gz version if
          appropriate, whether or not non-gz exists.
          - http://mailman.nginx.org/pipermail/nginx/2012-June/034102.html



          It seems that try_files requires the original file to work there and is not affected by gzip_static always.
          That's because try_files $uri =404 requires the $uri file to exist.
          - https://trac.nginx.org/nginx/ticket/1570




          This is my nginx.conf:



          events 
          worker_connections 768;


          http
          server
          # Enable static gzip
          gzip_static on;
          gunzip on;

          listen 8080 default_server;
          listen [::]:8080 default_server;

          root /home/user/projects/project1/build;

          location /
          try_files $uri /index.html;





          Run it with sudo nginx -t -c nginx.conf -p $PWD.



          Restart with sudo killall -9 nginx; sudo nginx -c nginx.conf -p $PWD; ps aux | grep nginx.






          share|improve this answer

























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "2"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f571733%2fnginx-gzip-static-why-are-the-non-compressed-files-required%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            4














            It's possible that you've found a bug. But in general you want both files anyway, for three reasons:



            1. A few clients won't request compressed data, and if you force it on them with gzip_static always; they might not understand it.

            2. To ensure that the file is always found, and the request isn't passed upstream to Rails or being caught by the 404 handler (the possible bug). One of which is probably what's happening.

            3. Having nginx compress or uncompress the file at runtime means it must do so repeatedly, eating up valuable CPU that could be used to run your application. It's much less CPU intensive to simply send a static resource.





            share|improve this answer

























            • Thanks. Yes, the request is being caught by the handler. I'm pretty sure because when I replaced the try_files directive with try_files $uri @named_proxy_loc; the request was sent to Rails.

              – tompave
              Feb 3 '14 at 2:15











            • Also, yes, I'm aware of the advantages, and I am indeed happy to have both versions of the assets on the server. I was just wondering if my configuration is ok or if I'm missing something.

              – tompave
              Feb 3 '14 at 2:15











            • As long as you have gzip_static on; and not always, and have both versions of the file, you should be fine.

              – Michael Hampton
              Feb 3 '14 at 2:16






            • 2





              try_files works before gzip_static therefore it looks for uncompressed file.

              – Alexey Ten
              Jul 11 '14 at 4:56















            4














            It's possible that you've found a bug. But in general you want both files anyway, for three reasons:



            1. A few clients won't request compressed data, and if you force it on them with gzip_static always; they might not understand it.

            2. To ensure that the file is always found, and the request isn't passed upstream to Rails or being caught by the 404 handler (the possible bug). One of which is probably what's happening.

            3. Having nginx compress or uncompress the file at runtime means it must do so repeatedly, eating up valuable CPU that could be used to run your application. It's much less CPU intensive to simply send a static resource.





            share|improve this answer

























            • Thanks. Yes, the request is being caught by the handler. I'm pretty sure because when I replaced the try_files directive with try_files $uri @named_proxy_loc; the request was sent to Rails.

              – tompave
              Feb 3 '14 at 2:15











            • Also, yes, I'm aware of the advantages, and I am indeed happy to have both versions of the assets on the server. I was just wondering if my configuration is ok or if I'm missing something.

              – tompave
              Feb 3 '14 at 2:15











            • As long as you have gzip_static on; and not always, and have both versions of the file, you should be fine.

              – Michael Hampton
              Feb 3 '14 at 2:16






            • 2





              try_files works before gzip_static therefore it looks for uncompressed file.

              – Alexey Ten
              Jul 11 '14 at 4:56













            4












            4








            4







            It's possible that you've found a bug. But in general you want both files anyway, for three reasons:



            1. A few clients won't request compressed data, and if you force it on them with gzip_static always; they might not understand it.

            2. To ensure that the file is always found, and the request isn't passed upstream to Rails or being caught by the 404 handler (the possible bug). One of which is probably what's happening.

            3. Having nginx compress or uncompress the file at runtime means it must do so repeatedly, eating up valuable CPU that could be used to run your application. It's much less CPU intensive to simply send a static resource.





            share|improve this answer















            It's possible that you've found a bug. But in general you want both files anyway, for three reasons:



            1. A few clients won't request compressed data, and if you force it on them with gzip_static always; they might not understand it.

            2. To ensure that the file is always found, and the request isn't passed upstream to Rails or being caught by the 404 handler (the possible bug). One of which is probably what's happening.

            3. Having nginx compress or uncompress the file at runtime means it must do so repeatedly, eating up valuable CPU that could be used to run your application. It's much less CPU intensive to simply send a static resource.






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jul 11 '14 at 4:48

























            answered Feb 3 '14 at 2:08









            Michael HamptonMichael Hampton

            177k27322653




            177k27322653












            • Thanks. Yes, the request is being caught by the handler. I'm pretty sure because when I replaced the try_files directive with try_files $uri @named_proxy_loc; the request was sent to Rails.

              – tompave
              Feb 3 '14 at 2:15











            • Also, yes, I'm aware of the advantages, and I am indeed happy to have both versions of the assets on the server. I was just wondering if my configuration is ok or if I'm missing something.

              – tompave
              Feb 3 '14 at 2:15











            • As long as you have gzip_static on; and not always, and have both versions of the file, you should be fine.

              – Michael Hampton
              Feb 3 '14 at 2:16






            • 2





              try_files works before gzip_static therefore it looks for uncompressed file.

              – Alexey Ten
              Jul 11 '14 at 4:56

















            • Thanks. Yes, the request is being caught by the handler. I'm pretty sure because when I replaced the try_files directive with try_files $uri @named_proxy_loc; the request was sent to Rails.

              – tompave
              Feb 3 '14 at 2:15











            • Also, yes, I'm aware of the advantages, and I am indeed happy to have both versions of the assets on the server. I was just wondering if my configuration is ok or if I'm missing something.

              – tompave
              Feb 3 '14 at 2:15











            • As long as you have gzip_static on; and not always, and have both versions of the file, you should be fine.

              – Michael Hampton
              Feb 3 '14 at 2:16






            • 2





              try_files works before gzip_static therefore it looks for uncompressed file.

              – Alexey Ten
              Jul 11 '14 at 4:56
















            Thanks. Yes, the request is being caught by the handler. I'm pretty sure because when I replaced the try_files directive with try_files $uri @named_proxy_loc; the request was sent to Rails.

            – tompave
            Feb 3 '14 at 2:15





            Thanks. Yes, the request is being caught by the handler. I'm pretty sure because when I replaced the try_files directive with try_files $uri @named_proxy_loc; the request was sent to Rails.

            – tompave
            Feb 3 '14 at 2:15













            Also, yes, I'm aware of the advantages, and I am indeed happy to have both versions of the assets on the server. I was just wondering if my configuration is ok or if I'm missing something.

            – tompave
            Feb 3 '14 at 2:15





            Also, yes, I'm aware of the advantages, and I am indeed happy to have both versions of the assets on the server. I was just wondering if my configuration is ok or if I'm missing something.

            – tompave
            Feb 3 '14 at 2:15













            As long as you have gzip_static on; and not always, and have both versions of the file, you should be fine.

            – Michael Hampton
            Feb 3 '14 at 2:16





            As long as you have gzip_static on; and not always, and have both versions of the file, you should be fine.

            – Michael Hampton
            Feb 3 '14 at 2:16




            2




            2





            try_files works before gzip_static therefore it looks for uncompressed file.

            – Alexey Ten
            Jul 11 '14 at 4:56





            try_files works before gzip_static therefore it looks for uncompressed file.

            – Alexey Ten
            Jul 11 '14 at 4:56













            6














            Uncompressed files are not required on Nginx 1.6 with:



             location ~ .txt$ 
            gzip_static on;
            gunzip on;



            Both curl http://localhost/index.txt and curl -H "Accept-Encoding: gzip" http://localhost/index.txt | gunzip now work fine with just /srv/www/localhost/index.txt.gz in my root directory.






            share|improve this answer




















            • 4





              The gunzip directive is relatively new. And it had some bugs prior to the 1.6 stable release. Anyway, if you have the extra CPU to spend on it, go ahead, but it will almost always be faster to have the resource already (un)compressed and available to sendfile() immediately.

              – Michael Hampton
              Jul 10 '14 at 23:28












            • Have you benchmarked "it will almost always be faster". My own hunch is that it will be slower to have an uncompressed copy because, for a static HTTP server, CPU isn't traditionally the bottleneck compared to disk IO. As most clients will be using the compressed version, it is likely that it will already be cached. Even if it isn't, it's less data to read from the disk, so will be read quicker.

              – rjmunro
              Aug 23 '17 at 8:43






            • 1





              On Linux servers, the most accessed/recent files are cached on RAM thus, when doing benchmarks, after the first request, the subsequent ones will also be reading the file's content from RAM. So, my conclusion is that having both compressed and uncompressed is the optimal option, as no CPU time is involved and, practically, no slow disk I/O for the great majority of the requests (+99.999%).

              – Paulo Coghi
              Aug 23 '18 at 16:00
















            6














            Uncompressed files are not required on Nginx 1.6 with:



             location ~ .txt$ 
            gzip_static on;
            gunzip on;



            Both curl http://localhost/index.txt and curl -H "Accept-Encoding: gzip" http://localhost/index.txt | gunzip now work fine with just /srv/www/localhost/index.txt.gz in my root directory.






            share|improve this answer




















            • 4





              The gunzip directive is relatively new. And it had some bugs prior to the 1.6 stable release. Anyway, if you have the extra CPU to spend on it, go ahead, but it will almost always be faster to have the resource already (un)compressed and available to sendfile() immediately.

              – Michael Hampton
              Jul 10 '14 at 23:28












            • Have you benchmarked "it will almost always be faster". My own hunch is that it will be slower to have an uncompressed copy because, for a static HTTP server, CPU isn't traditionally the bottleneck compared to disk IO. As most clients will be using the compressed version, it is likely that it will already be cached. Even if it isn't, it's less data to read from the disk, so will be read quicker.

              – rjmunro
              Aug 23 '17 at 8:43






            • 1





              On Linux servers, the most accessed/recent files are cached on RAM thus, when doing benchmarks, after the first request, the subsequent ones will also be reading the file's content from RAM. So, my conclusion is that having both compressed and uncompressed is the optimal option, as no CPU time is involved and, practically, no slow disk I/O for the great majority of the requests (+99.999%).

              – Paulo Coghi
              Aug 23 '18 at 16:00














            6












            6








            6







            Uncompressed files are not required on Nginx 1.6 with:



             location ~ .txt$ 
            gzip_static on;
            gunzip on;



            Both curl http://localhost/index.txt and curl -H "Accept-Encoding: gzip" http://localhost/index.txt | gunzip now work fine with just /srv/www/localhost/index.txt.gz in my root directory.






            share|improve this answer















            Uncompressed files are not required on Nginx 1.6 with:



             location ~ .txt$ 
            gzip_static on;
            gunzip on;



            Both curl http://localhost/index.txt and curl -H "Accept-Encoding: gzip" http://localhost/index.txt | gunzip now work fine with just /srv/www/localhost/index.txt.gz in my root directory.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jul 11 '14 at 4:45

























            answered Jul 10 '14 at 22:43









            hendryhendry

            452923




            452923







            • 4





              The gunzip directive is relatively new. And it had some bugs prior to the 1.6 stable release. Anyway, if you have the extra CPU to spend on it, go ahead, but it will almost always be faster to have the resource already (un)compressed and available to sendfile() immediately.

              – Michael Hampton
              Jul 10 '14 at 23:28












            • Have you benchmarked "it will almost always be faster". My own hunch is that it will be slower to have an uncompressed copy because, for a static HTTP server, CPU isn't traditionally the bottleneck compared to disk IO. As most clients will be using the compressed version, it is likely that it will already be cached. Even if it isn't, it's less data to read from the disk, so will be read quicker.

              – rjmunro
              Aug 23 '17 at 8:43






            • 1





              On Linux servers, the most accessed/recent files are cached on RAM thus, when doing benchmarks, after the first request, the subsequent ones will also be reading the file's content from RAM. So, my conclusion is that having both compressed and uncompressed is the optimal option, as no CPU time is involved and, practically, no slow disk I/O for the great majority of the requests (+99.999%).

              – Paulo Coghi
              Aug 23 '18 at 16:00













            • 4





              The gunzip directive is relatively new. And it had some bugs prior to the 1.6 stable release. Anyway, if you have the extra CPU to spend on it, go ahead, but it will almost always be faster to have the resource already (un)compressed and available to sendfile() immediately.

              – Michael Hampton
              Jul 10 '14 at 23:28












            • Have you benchmarked "it will almost always be faster". My own hunch is that it will be slower to have an uncompressed copy because, for a static HTTP server, CPU isn't traditionally the bottleneck compared to disk IO. As most clients will be using the compressed version, it is likely that it will already be cached. Even if it isn't, it's less data to read from the disk, so will be read quicker.

              – rjmunro
              Aug 23 '17 at 8:43






            • 1





              On Linux servers, the most accessed/recent files are cached on RAM thus, when doing benchmarks, after the first request, the subsequent ones will also be reading the file's content from RAM. So, my conclusion is that having both compressed and uncompressed is the optimal option, as no CPU time is involved and, practically, no slow disk I/O for the great majority of the requests (+99.999%).

              – Paulo Coghi
              Aug 23 '18 at 16:00








            4




            4





            The gunzip directive is relatively new. And it had some bugs prior to the 1.6 stable release. Anyway, if you have the extra CPU to spend on it, go ahead, but it will almost always be faster to have the resource already (un)compressed and available to sendfile() immediately.

            – Michael Hampton
            Jul 10 '14 at 23:28






            The gunzip directive is relatively new. And it had some bugs prior to the 1.6 stable release. Anyway, if you have the extra CPU to spend on it, go ahead, but it will almost always be faster to have the resource already (un)compressed and available to sendfile() immediately.

            – Michael Hampton
            Jul 10 '14 at 23:28














            Have you benchmarked "it will almost always be faster". My own hunch is that it will be slower to have an uncompressed copy because, for a static HTTP server, CPU isn't traditionally the bottleneck compared to disk IO. As most clients will be using the compressed version, it is likely that it will already be cached. Even if it isn't, it's less data to read from the disk, so will be read quicker.

            – rjmunro
            Aug 23 '17 at 8:43





            Have you benchmarked "it will almost always be faster". My own hunch is that it will be slower to have an uncompressed copy because, for a static HTTP server, CPU isn't traditionally the bottleneck compared to disk IO. As most clients will be using the compressed version, it is likely that it will already be cached. Even if it isn't, it's less data to read from the disk, so will be read quicker.

            – rjmunro
            Aug 23 '17 at 8:43




            1




            1





            On Linux servers, the most accessed/recent files are cached on RAM thus, when doing benchmarks, after the first request, the subsequent ones will also be reading the file's content from RAM. So, my conclusion is that having both compressed and uncompressed is the optimal option, as no CPU time is involved and, practically, no slow disk I/O for the great majority of the requests (+99.999%).

            – Paulo Coghi
            Aug 23 '18 at 16:00






            On Linux servers, the most accessed/recent files are cached on RAM thus, when doing benchmarks, after the first request, the subsequent ones will also be reading the file's content from RAM. So, my conclusion is that having both compressed and uncompressed is the optimal option, as no CPU time is involved and, practically, no slow disk I/O for the great majority of the requests (+99.999%).

            – Paulo Coghi
            Aug 23 '18 at 16:00












            0














            Contrary to what @hendry says, I need to keep original files.



            I use nginx 1.15.9 (Ubuntu).



            gzip_static is compiled in:



            nginx -V 2>&1 | grep "--with-http_gzip_static_module



            gunzip is compiled in:



            nginx -V 2>&1 | grep "--with-http_gunzip_module".



            I have found this, though it may be outdated:




            try_files is not aware of gzip_static; but nginx will still
            honour it if both the non-gz and .gz files exist. This differs from
            the "normal" gzip_static handling which will serve the .gz version if
            appropriate, whether or not non-gz exists.
            - http://mailman.nginx.org/pipermail/nginx/2012-June/034102.html



            It seems that try_files requires the original file to work there and is not affected by gzip_static always.
            That's because try_files $uri =404 requires the $uri file to exist.
            - https://trac.nginx.org/nginx/ticket/1570




            This is my nginx.conf:



            events 
            worker_connections 768;


            http
            server
            # Enable static gzip
            gzip_static on;
            gunzip on;

            listen 8080 default_server;
            listen [::]:8080 default_server;

            root /home/user/projects/project1/build;

            location /
            try_files $uri /index.html;





            Run it with sudo nginx -t -c nginx.conf -p $PWD.



            Restart with sudo killall -9 nginx; sudo nginx -c nginx.conf -p $PWD; ps aux | grep nginx.






            share|improve this answer





























              0














              Contrary to what @hendry says, I need to keep original files.



              I use nginx 1.15.9 (Ubuntu).



              gzip_static is compiled in:



              nginx -V 2>&1 | grep "--with-http_gzip_static_module



              gunzip is compiled in:



              nginx -V 2>&1 | grep "--with-http_gunzip_module".



              I have found this, though it may be outdated:




              try_files is not aware of gzip_static; but nginx will still
              honour it if both the non-gz and .gz files exist. This differs from
              the "normal" gzip_static handling which will serve the .gz version if
              appropriate, whether or not non-gz exists.
              - http://mailman.nginx.org/pipermail/nginx/2012-June/034102.html



              It seems that try_files requires the original file to work there and is not affected by gzip_static always.
              That's because try_files $uri =404 requires the $uri file to exist.
              - https://trac.nginx.org/nginx/ticket/1570




              This is my nginx.conf:



              events 
              worker_connections 768;


              http
              server
              # Enable static gzip
              gzip_static on;
              gunzip on;

              listen 8080 default_server;
              listen [::]:8080 default_server;

              root /home/user/projects/project1/build;

              location /
              try_files $uri /index.html;





              Run it with sudo nginx -t -c nginx.conf -p $PWD.



              Restart with sudo killall -9 nginx; sudo nginx -c nginx.conf -p $PWD; ps aux | grep nginx.






              share|improve this answer



























                0












                0








                0







                Contrary to what @hendry says, I need to keep original files.



                I use nginx 1.15.9 (Ubuntu).



                gzip_static is compiled in:



                nginx -V 2>&1 | grep "--with-http_gzip_static_module



                gunzip is compiled in:



                nginx -V 2>&1 | grep "--with-http_gunzip_module".



                I have found this, though it may be outdated:




                try_files is not aware of gzip_static; but nginx will still
                honour it if both the non-gz and .gz files exist. This differs from
                the "normal" gzip_static handling which will serve the .gz version if
                appropriate, whether or not non-gz exists.
                - http://mailman.nginx.org/pipermail/nginx/2012-June/034102.html



                It seems that try_files requires the original file to work there and is not affected by gzip_static always.
                That's because try_files $uri =404 requires the $uri file to exist.
                - https://trac.nginx.org/nginx/ticket/1570




                This is my nginx.conf:



                events 
                worker_connections 768;


                http
                server
                # Enable static gzip
                gzip_static on;
                gunzip on;

                listen 8080 default_server;
                listen [::]:8080 default_server;

                root /home/user/projects/project1/build;

                location /
                try_files $uri /index.html;





                Run it with sudo nginx -t -c nginx.conf -p $PWD.



                Restart with sudo killall -9 nginx; sudo nginx -c nginx.conf -p $PWD; ps aux | grep nginx.






                share|improve this answer















                Contrary to what @hendry says, I need to keep original files.



                I use nginx 1.15.9 (Ubuntu).



                gzip_static is compiled in:



                nginx -V 2>&1 | grep "--with-http_gzip_static_module



                gunzip is compiled in:



                nginx -V 2>&1 | grep "--with-http_gunzip_module".



                I have found this, though it may be outdated:




                try_files is not aware of gzip_static; but nginx will still
                honour it if both the non-gz and .gz files exist. This differs from
                the "normal" gzip_static handling which will serve the .gz version if
                appropriate, whether or not non-gz exists.
                - http://mailman.nginx.org/pipermail/nginx/2012-June/034102.html



                It seems that try_files requires the original file to work there and is not affected by gzip_static always.
                That's because try_files $uri =404 requires the $uri file to exist.
                - https://trac.nginx.org/nginx/ticket/1570




                This is my nginx.conf:



                events 
                worker_connections 768;


                http
                server
                # Enable static gzip
                gzip_static on;
                gunzip on;

                listen 8080 default_server;
                listen [::]:8080 default_server;

                root /home/user/projects/project1/build;

                location /
                try_files $uri /index.html;





                Run it with sudo nginx -t -c nginx.conf -p $PWD.



                Restart with sudo killall -9 nginx; sudo nginx -c nginx.conf -p $PWD; ps aux | grep nginx.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Apr 29 at 12:44

























                answered Apr 29 at 12:12









                rofrolrofrol

                1012




                1012



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Server Fault!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f571733%2fnginx-gzip-static-why-are-the-non-compressed-files-required%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

                    Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

                    Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020