我在configurationVarnish时遇到了一些麻烦,在线文档不是很清楚(至less对我来说)。 我目前有一个Ubuntu服务器上的清漆caching设置。 我在同一台服务器上testing了本地Nginx的清漆,并且工作正常。 我想要做的就是使用Varnish作为configuration了Nginx的远程Web服务器的caching和反向代理。 我需要保留客户端请求的主机名,并将其传递给远程的Nginx Web服务器。 这可以在Nginx使用proxy_set_header主机和Apache通过使用ProxyPreserveHost在。 问题是我在我的远程Nginx上有许多不同的虚拟主机,服务器的DNS没有configuration其中的任何一个。 他们都是不同的,所以我需要确保从客户端请求的主机通过。 我很抱歉,如果这不清楚,但我是光油的全新,这是什么,就像我习惯与Apache或Nginx。 任何帮助将不胜感激。
这是我的default.vcl:
vcl 4.0; # Default backend definition. Set this to point to your content server. backend default { .host = "dns.of.remote.nginx.server"; .port = "80"; .probe = { .url = "/"; .timeout = 30s; .threshold = 8; } } sub vcl_recv { # Happens before we check if we have this in cache already. # # Typically you clean up the request here, removing cookies you don't need, # rewriting the request, etc. unset req.http.Cookie; set req.http.x-host = req.http.host; set req.http.x-url = req.url; set req.url = req.url; } sub vcl_backend_response { # Happens after we have read the response headers from the backend. # # Here you clean the response headers, removing silly Set-Cookie headers # and other mistakes your backend does. } sub vcl_deliver { # Happens when we have all the pieces we need, and are about to send the # response to the client. # # You can do accounting or modifying the final object here. }
首先,你通常不应该在varnish后端定义中指定DNS主机名。 它只在启动时解决,从不更新。 指定删除Nginx服务器的IP地址。
其次,你问的是Varnish的默认行为。 它是一个透明的cachingHTTP代理,因此它将通过客户端通过HTTP发送的任何Host头。