我有一个嵌入了已编译gzjs文件的静态html页面。使用过的预渲染,我的nginx文件是:
server {
listen 80;
listen [::]:80;
server_name www.example.com;
expires $expires;
root /usr/local/www/nginx-dist;
index index.html index.htm;
#proxy_set_header Host $http_host;
location / {
try_files $uri @prerender;
}
location @prerender {
proxy_set_header X-Prerender-Token MyToken;
set $prerender 0;
if ($http_user_agent ~* "googlebot|bingbot|googlebot-mobile|yandex|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|svg|eot)") {
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;
}
}
}
仅获取301和
<html><head></head><body></body></html>
通过googlebot提取。
根据prerender.io,“您需要切换到服务器(如Unicorn或Puma),该服务器可以启动多个进程或使用非阻塞I / O,以便在Prerender尝试呈现时不会出现死锁。飞行中的页面”, 有人可以建议如何针对我的情况吗?
谢谢。
答案 0 :(得分:0)
如果使用的是nginx配置,则无需切换到Unicorn / Puma,因为它们是Rails服务器。
看到此问题时,您可以将要测试的URL发送给我们的支持团队吗?我们将帮助您进行调查,并确保一切正常。只需发送电子邮件至support@prerender.io,我们将竭诚为您服务!
答案 1 :(得分:0)
在官方支持的帮助下,我最终的nginx文件是:
server {
listen 80;
listen [::]:80;
server_name www.YOURSITE.com;
expires $expires;
root /usr/local/www/nginx-dist;
index index.html index.htm;
proxy_set_header Host $http_host;
location / {
if ($uri ~* "\.(php|jsp)") {
return 404;
}
proxy_set_header X-Prerender-Token YOURTOKEN;
set $prerender 0;
if ($http_user_agent ~* "googlebot|Googlebot-Image|googlebot-mobile|Google-Structured-Data-Testing-Tool|AdsBot-Google-Mobile|Mediapartners-Google|bingbot|MSNBot|msnbot-media|AdsBot-Google-Mobile|yandex|baiduspider|Baiduspider-mobile|Baiduspider-image|Baiduspider-video|Baiduspider-news|Baiduspider-favo|Baiduspider-cpro|twitterbot|facebot|facebookexternalhit|rogerbot|linkedinbot|embedly|quora link preview|showyoubot|outbrain|pinterest|slackbot|tumblr|xml-sitemaps|vkShare|W3C_Validator|redditbot|Slack-ImgProxy|Slackbot-LinkExpanding|Site
Analyzer|SiteAnalyzerBot|Viber|Whatsapp|Telegram|Slurp|Slurp China|Discordbot|Sogou web spider|Sogou Pic Spider|Sogou Push Spider|YoudaoBot|YoudaoFeedFetcher|Sosospider|Sosoimagespider|360Spider|Speedy Spider|HuaweiSymantecSpider|iaskspider") {
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|svg|eot)") {
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 .* /https://$server_name$request_uri? break;
proxy_pass http://$prerender;
}
try_files $uri $uri/ /index.html;
}
}