如何配置 Varnish,以便对匹配“*.css”的请求的所有响应都在客户端的浏览器中缓存 30 天?
我想要实现的是让 Varnish 设置正确的“Expires:”和/或“Cache-Control”设置,以便所有 CSS:s 都缓存 30 天,而不管后端对这些对象。
情况是:
我正在构建 PHP 应用程序,并且需要 http 缓存。
Varnish 很棒,很多人告诉我 Varnish 将缓存数据存储在 RAM 中。但我希望它缓存在硬盘中。
有什么方法可以将 Varnish 缓存数据存储在硬盘中?
如何监控 memcached 以了解是否/发生了多少次驱逐,以及使用/释放了多少内存。
我们正在使用 Newrelic 来衡量我们的 Python/Django 应用程序性能。Newrelic 报告说,在我们的系统中,“Memcached”正在平均12ms响应命令。
深入到前十个左右的 Web 视图(按请求数),我可以看到有些Memcache get占30ms; 我无法Memcache get在小于10ms.
有关系统架构的更多详细信息:
~0.5msMemcached 的响应时间不是10ms很慢吗?
据我了解,如果您认为“Memcache 太慢”那么“您做错了”。那我做错了吗?
这是memcache-top命令的输出:
memcache-top v0.7 (default port: 11211, color: on, refresh: 3 seconds)
INSTANCE USAGE HIT % CONN TIME EVICT/s GETS/s SETS/s READ/s WRITE/s
cache1:11211 37.1% 62.7% 10 5.3ms 0.0 73 9 3958 …Run Code Online (Sandbox Code Playgroud) 来自iis.net 的引用:The ASP.NET page output cache is separate from the IIS 7 output cache. In applications that use the Integrated ASP.NET mode, the ASP.NET page output cache can be used programmatically for any content-type, much like the IIS 7 output cache.
那么我什么时候选择使用 IIS 输出缓存,什么时候更喜欢 ASP.net 输出缓存?也不清楚他们写了什么 asp.net 缓存“可用于任何内容类型”?
我有一个服务器块,我的站点所在的位置。在该块内,我添加了一个location块,如下所示:
server {
...
location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
expires 30d;
add_header Pragma public;
add_header Cache-Control "public";
}
...
}
Run Code Online (Sandbox Code Playgroud)
当我用 Y 检查过期标头时!慢什么都没有缓存!
注意:我在测试之前重新加载了我的配置文件。
编辑 1:
我注意到更改任何静态文件不会反映浏览器的新更改。这个缓存是指服务器端缓存吗?我们不能在客户端浏览器上缓存吗?
编辑2:
HTTP/1.0 200 OK
Server: nginx
Date: Tue, 23 Sep 2014 07:41:20 GMT
Content-Type: image/png
Content-Length: 5597
Last-Modified: Wed, 30 Jul 2014 22:50:19 GMT
ETag: "53d976ab-15dd"
Accept-Ranges: bytes
Age: 30396
Connection: close
Run Code Online (Sandbox Code Playgroud)
编辑 3:
完整的 nginx 配置:
# You may add here your
# server {
# ...
# …Run Code Online (Sandbox Code Playgroud) 我们有两个(有时甚至更多)应用程序争夺操作系统页面缓存。特别是 ElasticSearch 非常依赖于操作系统页面缓存。在低延迟情况下,缓存未命中可能会影响性能。ES 是节点上唯一的低延迟应用程序,因此它需要操作系统页面缓存。由于整个索引无法放入 RAM 中,因此使用预热器来填充缓存,但几个小时后,这些缓存被其他应用程序丢弃。
我的一些想法和想法:
可以为缓存开辟预定义 RAM 块的专用文件系统将是理想的选择。但是,由于 ES/Lucene 的设计限制,我目前对购买专用节点的任何事情都持开放态度。
我喜欢将 nginx 作为本地代理服务器运行,如果上游服务器不可用,则提供陈旧的缓存文件。
这很有效,除了本地机器重新启动,而互联网连接出现故障。在这种情况下,nginx 根本不会启动,说“在上游找不到主机......”。
在每种情况下我都需要 nginx 启动,否则无法在上游连接失败时提供陈旧的缓存。
那么如何让nginx在启动时忽略连接错误呢?
我们有两个具有独立本地缓存的 Nginx 服务器,用于缓存图像。缓存大小的非托管增长会定期出现问题。此大小可能远远大于max_size在nginx.conf。结果缓存占用了所有可用磁盘空间。
我想了解这个问题的原因可能是什么。
代理缓存配置 ( nginx.conf):
proxy_cache_path /opt2/nginx-cache-images1 max_size=150g levels=2:2 keys_zone=images1:1024m inactive=24h;
proxy_temp_path /opt2/proxy_temp 1 2;
Run Code Online (Sandbox Code Playgroud)
大小/opt2/nginx-cache-images1约为 200GB。
站点位置配置:
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Is-Referer-Search-Engine $is_referer_search_engine;
proxy_hide_header Set-Cookie;
proxy_hide_header Content-Disposition;
proxy_pass http://ua-image-proxy;
default_type image/jpeg;
proxy_cache images1;
proxy_cache_key ua$request_uri$is_referer_search_engine;
proxy_cache_valid 200 24h;
proxy_cache_valid 301 24h;
proxy_cache_valid 404 1h;
}
Run Code Online (Sandbox Code Playgroud)
Nginx 版本:1.7.7 和 1.7.9。它是在 Ubuntu 14.04 上编译的。
所以,我已经像这样设置了 FastCGI 缓存:
location ~ \.php(/.*)?$ {
fastcgi_cache RWI;
fastcgi_cache_valid 200 60m;
set $nocache 0;
if ($request_method = POST)
{
set $nocache 1;
}
if ($http_cookie ~ (rwi_userid*|rwi_password*)) {
set $nocache 1;
}
if ($request_uri ~* "/(vb/admincp/)") {
set $nocache 1;
}
fastcgi_no_cache $nocache;
fastcgi_cache_bypass $nocache;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass "unix:/var/www/vhosts/system/{domain}/php-fpm.sock";
include /etc/nginx/fastcgi.conf;
}
Run Code Online (Sandbox Code Playgroud)
在server{}块的顶部,我有:
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=RWI:100m inactive=60m;
fastcgi_cache_key "$scheme$request_method$host$request_uri";
add_header X-Cache $upstream_cache_status;
Run Code Online (Sandbox Code Playgroud)
问题是我的 PHP 脚本 (vBulletin) 总是发送 Pragma & Cache-Control private。当上述规则不适用时,有没有办法忽略这些标头并强制 FastCGI …
cache ×10
nginx ×4
memcached ×2
varnish ×2
asp.net ×1
disk-cache ×1
fastcgi ×1
filesystems ×1
iis ×1
linux ×1
memory ×1
performance ×1
php-fpm ×1
python ×1
web-server ×1