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

                    Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

                    Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

                    What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company