我们的网站与棱角,需要渲染搜索机器人和其他应用程序,如skype,这可以使页面预览。我们使用nginx,它设置了将请求从机器人发送到预发布程序,并安装在我们的服务器上。但在这种情况下,预录一页大约需要15秒。
那么,问题是预存器的设置缓存结果如何?
我已经尝试过了:将缓存设置放到frontend.conf中
proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=STATIC:10m max_size=1G;
proxy_temp_path /var/lib/nginx/proxy 1 2;
server {
location @prerender {
.....................
proxy_cache STATIC;
proxy_cache_valid 1d;
if ($prerender = 1) {
rewrite .* /$scheme://$host:$server_port$request_uri? break;
proxy_pass http://10.0.2.2:3000;
}}}
使用工作prerender.io的10.0.2.2服务器
我试着通过另一个nginx来做这件事,它的设置就像缓存代理。在frotnend.conf中,我注释所有缓存设置,并将它们放入其他nginx中。但是我仍然有同样的问题,页面呈现需要15秒,而nginx不进行任何缓存。
UDP.
我尝试了另一种nginx配置,但仍然有问题。模式看起来像
web-browser(http://myapp.local) > |AppServer(frontend) is a virtual Server|(proxy_pass) > to > |nginx with proxy cache| > to > |prerender|
proxy-cache.conf
proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=STATIC:10m max_size=1G;
proxy_temp_path /var/lib/nginx/proxy 1 2;
server {
..............................
location / {
proxy_cache STATIC;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Expires;
proxy_cache_methods GET;
proxy_cache_valid any 1d; # 200
#proxy_cache_key $host$uri$is_args$args;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_pass http://127.0.0.1:3000;
}}
我为缓存配置日志记录。当我在日志中向服务器发出请求时,我得到以下内容:
GET /http://myweb.local:80/ HTTP/1.0 "302" 20 "-" "10.0.2.2" "skype" "-" "MISS" "127.0.0.1:3000" "0.388" "0.389"
GET /http://myweb.local:80/en/ HTTP/1.0 "200" 14685 "-" "10.0.2.2" "skype" "-" "MISS" "127.0.0.1:3000" "1.261" "1.263"
GET /http://myweb.local:80/ HTTP/1.0 "302" 20 "-" "10.0.2.2" "skype" "-" "HIT" "-" "-" "0.001"
GET /http://myweb.local:80/en/ HTTP/1.0 "200" 14689 "-" "10.0.2.2" "skype" "-" "MISS" "127.0.0.1:3000" "1.249" "1.251"
在原木的预光机中:
2016-06-15T14:05:57.880Z getting http://myweb.local:80/en/
2016-06-15T14:05:59.131Z got 200 in 1251ms for http://myweb.local:80/en/
2016-06-15T14:06:00.332Z getting http://myweb.local:80/en/
2016-06-15T14:06:01.885Z got 200 in 1553ms for http://myweb.local:80/en/
发布于 2016-06-17 08:34:57
我解决了这个问题。它需要添加另一个忽略头部proxy_ignore_headers Set-Cookie;。因此,通过nginx实现缓存预存器的配置将是:
proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=2g;
server {
.......................
location / {
try_files $uri @prerender;
}
location @prerender {
set $prerender 0;
.......................
proxy_cache STATIC;
proxy_cache_valid any 1d;
proxy_ignore_headers Cache-Control;
proxy_ignore_headers X-Accel-Expires;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers Expires;
proxy_cache_key $host$uri$is_args$args;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
if ($prerender = 1) {
rewrite .* /$scheme://$host:$server_port$request_uri? break;
proxy_pass http://10.0.2.2:3000;
}
发布于 2016-06-15 11:01:13
将缓存添加到预存服务器本身是相当容易的,s3和内存缓存工作从盒子里出来。
如果您需要nginx来处理缓存,我认为如果您将其放在问题标题中,您将获得更好的答案。
https://stackoverflow.com/questions/37828419
复制相似问题