prender.io nginx配置不缓存页面

时间:2015-11-12 09:39:39

标签: nginx prerender

我正在使用prerender.io和nginx和angularjs,但prerender仪表板仍然没有显示任何缓存的页面,并且还要求我安装令牌,我已经完成了。

我的服务器只提供静态资产。

这个

server {
listen  80;

access_log  /var/log/nginx/access.log;
error_log  /var/log/nginx/error.log;

server_name www.domainname.com;
return 301 https://www.domainname.com$request_uri;
root /home/<username>/app/;
index  index.html;

location / {
  autoindex off;
  try_files $uri @prerender;
#      try_files $uri /index.html =404;
}

location @prerender {
    proxy_set_header X-Prerender-Token <token>;

    set $prerender 0;
    if ($http_user_agent ~* "baiduspider|twitterbot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|vkShare|W3C_Validator") {
        set $prerender 1;
    }
    if ($args ~ "_escaped_fragment_") {
        set $prerender 1;
    }
    if ($http_user_agent ~ "Prerender") {
        set $prerender 0;
    }
    if ($uri ~ "\.(js|css|xml|less|png|jpg|jpeg|gif|pdf|doc|txt|ico|rss|zip|mp3|rar|exe|wmv|doc|avi|ppt|mpg|mpeg|tif|wav|mov|psd|ai|xls|mp4|m4a|swf|dat|dmg|iso|flv|m4v|torrent|ttf|woff)") {
        set $prerender 0;
    }

    #resolve using Google's DNS server to force DNS resolution and prevent caching of IPs
    resolver 8.8.8.8;

    if ($prerender = 1) {

        #setting prerender as a variable forces DNS resolution since nginx caches IPs and doesnt play well with load balancing
        set $prerender "service.prerender.io";
        rewrite .* /$scheme://$host$request_uri? break;
        proxy_pass http://$prerender;
    }
    if ($prerender = 0) {
        rewrite .* /index.html break;
    }
}

# these settings are from https://github.com/h5bp/server-configs-nginx/blob/master/h5bp/location/expires.conf
# feel free to change as much as you like
# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
  expires -1;
  access_log logs/static.log;
}

# Feed
location ~* \.(?:rss|atom)$ {

 expires 1h;
  add_header Cache-Control "public";
}

# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
  expires 1M;
  access_log off;
  add_header Cache-Control "public";
}

# CSS and Javascript
location ~* \.(?:css|js)$ {
  expires 1y;
  access_log off;
  add_header Cache-Control "public";
}
}

0 个答案:

没有答案