我刚刚在我的开发服务器上安装了清漆,并且它在不更改任何配置的情况下运行。所以现在它只是要求Apache做出响应并将其传回去。
嗯,我是一个新手,我试图缓存javascript,css和图像以测试清漆。我的问题是如果我写return(查找);在vcl_recv中给出了服务清漆重启的错误!!
vcl 4.0;
# Default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "80";
}
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.
#hash_data(req.url);
#if (req.http.host) {
# hash_data(req.http.host);
#} else {
# hash_data(server.ip);
#}
return (lookup);
}
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.
}
default.vcl中的此配置为我提供了重启时的下一个错误:
Job for varnish.service failed. See 'systemctl status varnish.service' and 'journalctl -xn' for details.
请帮帮我!!
答案 0 :(得分:0)
您可以执行以下操作:
sub vcl_recv {
if (req.url ~ "(?i)\.(jpeg|jpg|png|gif|ico|js|css)$") {
unset req.http.Cookie;
return (hash);
} else {
return (pass);
}
}
对于扩展答案,您可能希望查看https://serverfault.com/a/551283/426146中的清漆 3 的答案。
答案 1 :(得分:0)
问题是在default.vcl中,端口为80。 该端口必须是Web服务器正在侦听的端口,例如8080。 必须在8080中配置Web服务器。 在Debian中,您的/etc/systemd/system/varnish.service文件具有您必须更改为80的端口
ExecStart = / usr / sbin / varnished -j unix,user = vcache -F -a:80 -T localhost:6082 -f /etc/varnish/default.vcl -S / etc / varnish / secret -s malloc ,512m
然后使用浏览器将您连接到80的清漆和8080中的清漆询问Web服务器的页面和文件(第一次命中后缓存)。
如果文件不存在,请运行:
cp /lib/systemd/system/varnish.service / etc / systemd / system /
systemctl守护进程重新加载&& systemctl状态清漆
并且开始使用该文件,然后您可以在/etc/varnish/default.vcl中输入代码