nginx + varnish,为ssl优化cachingurl

我有一个工作清漆caching为我的网站,与不希望的副作用,请求与http域名caching与一个特定的url,并要求与另一个urlhttps。 这样我最终在caching中的双重对象,我想问一些如何优化这种行为的最佳做法。

详细我有nginx内的两个虚拟主机相同的域侦听端口80和443每个。 请求被代理传递给清漆:

proxy_pass http://varnish:8101/VirtualHostBase/http/example.com:80/path/VirtualHostRoot/; 

 proxy_pass http://varnish:8101/VirtualHostBase/https/example.com:443/path/VirtualHostRoot/; 

在varnish.vcl我检查请求的主机,并设置右后端,因为有多个。

 if (req.http.host == "example.com") { set req.backend = backend_0; } 

后端是一个Zope / Plone服务器。 页面caching正确varnish,但我有/VirtualHostBase/http/example.com:80/path/VirtualHostRoot/logo.png和/VirtualHostBase/https/example.com:443/path/VirtualHostRoot/一个条目在我的varnishlog(RxURL)中的logo.png。

Plone清除条目时,只清除ssl版本,因为每个login用户都必须使用https。 http条目保持到年龄无效。

是否有可能通过重写URL来将http和https请求合并成一个清漆对象? 为了节省空间和做一个成功的清除。 也许有人可以给我一个提示如何解决这个问题!

Varnish根据其req.url和它们的req.http.Host (如果存在,否则使用server.ip )标识不同的实体。 你想要的是这样的:

 sub vcl_hash { #Example URL is: # http://varnish:8101/VirtualHostBase/http/example.com:80/path/VirtualHostRoot/ #req.url contains only: # /VirtualHostBase/http/example.com:80/path/VirtualHostRoot/ #after transform, this will become: # /VirtualHostBase/fakescheme/example.com:fakeport/path/VirtualHostRoot/ hash_data(regsub(regsub(req.url,":(80|443)/",":fakeport/"),"/https?/","/fakescheme/")); #equivalent of "hash URL" #Below here, copied from default.vcl if (req.http.host) { hash_data(req.http.host); } else { hash_data(server.ip); } return (hash); } 

一个想法你可以如何实现这一点:

在这里输入图像说明

所以你需要设置:

  • 一个清漆逆向代理
    • 侦听端口*:80并使用后端localhost:8080
  • 一个Nginx的networking服务器
    • 侦听端口*:443并转发到本地主机:80
    • 监听端口localhost:8080并为网站提供服务

实际上Nginx已经可以configuration为caching逆向代理。 但是,如果您想拥有特定的caching规则,则从caching等清除单个对象的能力将成为更好的解决scheme。

暗示:

您必须检查您的网站是否适用于http和https的相同caching对象。 如果网站使用外部内容的绝对URL(例如embedded式媒体资源)提供HTML,CSS或JavaScript,则不是这样。 如您所知,浏览器不喜欢将HTTP资源embeddedHTTPS网站。