根据协议设置清漆后端

根据协议设置清漆后端

我有一个内置应用程序。我在http 和httpsnode.js端口上运行它。如果我在 URL 中提供端口号,两者都可以正常工作。80008003

tcp6       0      0 :::8000                 :::*                    LISTEN      4947/node       
tcp6       0      0 :::8003                 :::*                    LISTEN      4947/node

我想在节点前面设置一个清漆,以便我可以从 URL 中删除端口号。

下面是我用 varnish 设置的基本配置。

backend newstack {
  .host = "127.0.0.1";
  .port = "8000";
  .connect_timeout = 1s;
  .first_byte_timeout = 5s;
  .between_bytes_timeout = 2s;
}
backend sslnewstack {
  .host = "127.0.0.1";
  .port = "8003";
  .connect_timeout = 1s;
  .first_byte_timeout = 5s;
  .between_bytes_timeout = 2s;
}
/*
*
* Next, configure the "receive" subroutine.
*
*/
sub vcl_recv {
# Use the backend we set up above to answer the request if it's not cached.
        if(req.http.host ~ "dev.domain.com" && req.http.X-Forwarded-Proto ~ "(?i)http"){
          set req.backend = newstack;
          return(pipe);
        }
        if(req.http.host ~ "dev.domain.com" && req.http.X-Forwarded-Proto ~ "(?i)https"){
          set req.backend = sslnewstack;
          return(pass);
        }
}
sub vcl_miss {
    return(fetch);
}
/*
*
* Now, let's set up a subroutine to deal with cache hits.
*
*/
sub vcl_hit {
   return(deliver);
}
/*
*
* This is the subroutine which will fetch a response from the backend.
* It's pretty fancy because this is where the basic logic for caching is set.
* 
*/
sub vcl_fetch {

    # Get the response. Set the cache lifetime of the response to 1 hour.
    set beresp.ttl = 1h;

    # Indicate that this response is cacheable. This is important.
    set beresp.http.X-Cacheable = "NO";

    # Some backends *cough* Django *cough* will assign a Vary header for
    # each User-Agent which visits the site. Varnish will store a separate
    # copy of the page in the cache for each instance of the Vary header --
    # one for each User-Agent which visits the site. This is bad. So we're
    # going to strip away the Vary header. 
    unset beresp.http.Vary;

    # Now pass this backend response along to the cache to be stored and served.
    return(deliver);
}
/*
*
* Finally, let's set up a subroutine which will deliver a response to the client.
* 
*/
sub vcl_deliver {
    return(deliver);
}

但它不起作用。我这里遗漏了什么。

答案1

您没有意识到 Varnish 不支持 SSL。您需要利用 Nginx 或 Hitch 来使用 SSL 终止。

相关内容