Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7770175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:20:40+00:00 2026-06-01T16:20:40+00:00

Im trying to provide gzip compression using varnish cache. But when I set content-encoding

  • 0

Im trying to provide gzip compression using varnish cache. But when I set content-encoding as gzip using my below mentioned configuration for varnish (default.vcl). Browser failed to download those content for which i set content-encoding as gzipped.

Varnish configuration file:

backend default {
      .host = "127.0.0.1";
      .port = "9000";
}

backend socketIO {
      .host = "127.0.0.1";
      .port = "8083";
}

acl purge {
        "127.0.0.1";
        "192.168.15.0"/24;
}

sub vcl_fetch {
    /* If the request is for pictures, javascript, css, etc */
        if (req.url ~ "^/public/" || req.url ~ "\.js"){     
        unset req.http.cookie;      
        set beresp.http.Content-Encoding= "gzip";   
        set beresp.ttl = 86400s;
        set beresp.http.Cache-Control = "public, max-age=3600";
        /*set the expires time to response header*/
        set beresp.http.expires=beresp.ttl;     
                /* marker for vcl_deliver to reset Age: */
                set beresp.http.magicmarker = "1";
    }

    if (!beresp.cacheable) {
         return (pass);
    }
    return (deliver);
}
sub vcl_deliver {
    if (resp.http.magicmarker) {
        /* Remove the magic marker */
        unset resp.http.magicmarker;

        /* By definition we have a fresh object */
        set resp.http.age = "0";
    }

     if(obj.hits > 0) {
        set resp.http.X-Varnish-Cache = "HIT";
     }else {
        set resp.http.X-Varnish-Cache = "MISS";
     }

    return (deliver);
}

sub vcl_recv {
    if (req.http.x-forwarded-for) {
        set req.http.X-Forwarded-For =
            req.http.X-Forwarded-For ", " client.ip;
        } else {
        set req.http.X-Forwarded-For = client.ip;
        }
        if (req.request != "GET" &&
            req.request != "HEAD" &&
            req.request != "PUT" &&
            req.request != "POST" &&
            req.request != "TRACE" &&
            req.request != "OPTIONS" &&
            req.request != "DELETE") {
            /* Non-RFC2616 or CONNECT which is weird. */
            return (pipe);
        }
    # Pass requests that are not GET or HEAD
    if (req.request != "GET" && req.request != "HEAD") {
         return(pass);
    }        

    #pipe websocket connections directly to Node.js
    if (req.http.Upgrade ~ "(?i)websocket") {
        set req.backend = socketIO;
        return (pipe);
    }   

     # Properly handle different encoding types
        if (req.http.Accept-Encoding) {
        if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg|js|css)$") {
            # No point in compressing these
            remove req.http.Accept-Encoding;
        } elsif (req.http.Accept-Encoding ~ "gzip") {
            set req.http.Accept-Encoding = "gzip";
        } elsif (req.http.Accept-Encoding ~ "deflate") {
            set req.http.Accept-Encoding = "deflate";
        } else {
            # unkown algorithm
            remove req.http.Accept-Encoding;
        }
        }

    # allow PURGE from localhost and 192.168.15...
        if (req.request == "PURGE") {
                if (!client.ip ~ purge) {
                        error 405 "Not allowed.";
                }
                return (lookup);
        }
    return (lookup);
}

sub vcl_hit {
        if (req.request == "PURGE") {
                purge_url(req.url);
                error 200 "Purged.";
        }
}

sub vcl_miss {
        if (req.request == "PURGE") {
                purge_url(req.url);
                error 200 "Purged.";
        }
}

sub vcl_pipe {
     if (req.http.upgrade) {
         set bereq.http.upgrade = req.http.upgrade;
     }
 }

Response Header:

Cache-Control:public, max-age=3600
Connection:keep-alive
Content-Encoding:gzip
Content-Length:11520
Content-Type:application/javascript
Date:Fri, 06 Apr 2012 04:53:41 GMT
ETag:"1330493670000--987570445"
Last-Modified:Wed, 29 Feb 2012 05:34:30 GMT
Server:Play! Framework;1.2.x-localbuild;dev
Via:1.1 varnish
X-Varnish:118464579 118464571
X-Varnish-Cache:HIT
age:0
expires:86400.000

Any suggestion on how to fix it and how to provide gzip compression using varnish.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:20:41+00:00Added an answer on June 1, 2026 at 4:20 pm

    Varnish Cache 3.0 does most of the handling of Accept-Encoding automatically and you shouldn’t mess with it.

    Basically, if you want Varnish to compress an object just set beresp.do_gzip in vcl_fetch and it will compress it before storing it in cache. Uncompression happens automatically when needed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to provide client side validation for password using jquery, but the
I'm trying to use ThreadLocal to provide thread safety to pre-existing non-thread-safe classes, but
I am trying to modify the default Soloritas templates to provide a UI for
I'm trying to gzip some data using Node.js... Specifically, I have data in 'buf'
I am trying to provide my own labelFunction for a CategoryAxis programatically but am
i'm trying to provide different static initializations for classes in a hierarchy, but when
Can someone provide me with an optimized .htaccess configuration that handles compression, browser caching,
I'm trying to provide a member variable as a default value for a class
I am trying to provide login using facebook option to my website users. So,
I'm trying to provide a Logger using a queue system and Timer to to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.