Prerender + AngularJS - 爬虫超时
Prerender + AngularJS - Crawlers time out
关于设置的信息:
我已经在自己的服务器上成功安装了 prerender (https://github.com/prerender/prerender),Ubuntu 16.
这是我的 .htaccess,它会在检测到爬虫时将 url 重写到预渲染。示例:http://www.example.nl/63/Merry becomes http://example.nl:3000/http://www.example.nl/63/Merry
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|redditbot|slackbot|msnbot|googlebot|duckduckbot|bingbot|rogerbot|linkedinbot|embedly|flipboard|tumblr|bitlybot|SkypeUriPreview|nuzzel|Discordbot|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=$
RewriteRule ^(.*)$ http://example.nl:3000/http://www.example.nl/? [R=301,L]
#RewriteRule ^(.*)$ http://art.example.net/? [R=301,L]
RewriteRule ^(.*)/(.*)$ /#/ [NC,L]
问题:
使用预呈现时,元数据未在 Skype、Reddit、Twitter 上加载。将 url 重写为旧的 PHP 网站:http://art.example.net(目前在 htaccess 中评论)确实有效。因为 PHP 和 Angular 网站上的所有元标记都是相同的,预呈现器很可能是问题的原因。
来自 Twitter (https://cards-dev.twitter.com/validator using url: http://example.nl/63/Merry) 使用 Prerender 的错误示例:
ERROR: Failed to fetch page due to: HttpConnectionTimeout
WARN: this card is redirected to http://example.nl:3000/http://www.example.nl/63/Merry
重定向到 art.example.net 时的 Twitter(也使用主 URL:http://example.nl/63/Merry)
INFO: Page fetched successfully
INFO: 19 metatags were found
INFO: twitter:card = summary_large_image tag found
INFO: Card loaded successfully
WARN: this card is redirected to http://art.example.net/63/Merry
使用 PHP 版本有效,并且正在加载所有元数据。
将来我想完全删除 PHP 网站,所以我真的很希望它能与 Prerender 一起工作。
Prerender 在 Discord 和 Postman 中确实有效(使用修改后的用户代理 header)。我只是不知道为什么它对某些其他代理不起作用。
解决方法:
Twitter 和其他爬虫无法处理 url 中的点和“:”。所以纯 IP 地址和端口号是不允许的。
要解决此问题,您可以创建一个子域,它重定向到 Node.js 应用程序
我的子域 Apache 虚拟主机:
<VirtualHost *:80>
ServerAdmin info@example.net
ServerName prerender.example.net
ServerAlias prerender.example.net
ProxyPass / http://localhost:3000/ connectiontimeout=5 timeout=30
</VirtualHost>
连同 prerender.io 他们自己的回答,我设法让它发挥作用。
虽然代理和重定向对于社交媒体爬虫来说并不重要,因为 URL 已经粘贴在那里了。使用代理标记是一种很好的做法。
您的重写规则应该是代理,而不是重定向。重定向到您的预呈现服务器会导致各种问题,包括告诉 Google 将用户从搜索结果直接发送到您的预呈现服务器(这真的很糟糕!)。
重写规则部分应该是:
RewriteRule ^(.*)$ http://example.nl:3000/http://www.example.nl/? [P,L]
关于设置的信息:
我已经在自己的服务器上成功安装了 prerender (https://github.com/prerender/prerender),Ubuntu 16.
这是我的 .htaccess,它会在检测到爬虫时将 url 重写到预渲染。示例:http://www.example.nl/63/Merry becomes http://example.nl:3000/http://www.example.nl/63/Merry
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_USER_AGENT} baiduspider|facebookexternalhit|twitterbot|redditbot|slackbot|msnbot|googlebot|duckduckbot|bingbot|rogerbot|linkedinbot|embedly|flipboard|tumblr|bitlybot|SkypeUriPreview|nuzzel|Discordbot|quora\ link\ preview|showyoubot|outbrain|pinterest [NC,OR]
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=$
RewriteRule ^(.*)$ http://example.nl:3000/http://www.example.nl/? [R=301,L]
#RewriteRule ^(.*)$ http://art.example.net/? [R=301,L]
RewriteRule ^(.*)/(.*)$ /#/ [NC,L]
问题:
使用预呈现时,元数据未在 Skype、Reddit、Twitter 上加载。将 url 重写为旧的 PHP 网站:http://art.example.net(目前在 htaccess 中评论)确实有效。因为 PHP 和 Angular 网站上的所有元标记都是相同的,预呈现器很可能是问题的原因。
来自 Twitter (https://cards-dev.twitter.com/validator using url: http://example.nl/63/Merry) 使用 Prerender 的错误示例:
ERROR: Failed to fetch page due to: HttpConnectionTimeout
WARN: this card is redirected to http://example.nl:3000/http://www.example.nl/63/Merry
重定向到 art.example.net 时的 Twitter(也使用主 URL:http://example.nl/63/Merry)
INFO: Page fetched successfully
INFO: 19 metatags were found
INFO: twitter:card = summary_large_image tag found
INFO: Card loaded successfully
WARN: this card is redirected to http://art.example.net/63/Merry
使用 PHP 版本有效,并且正在加载所有元数据。
将来我想完全删除 PHP 网站,所以我真的很希望它能与 Prerender 一起工作。 Prerender 在 Discord 和 Postman 中确实有效(使用修改后的用户代理 header)。我只是不知道为什么它对某些其他代理不起作用。
解决方法:
Twitter 和其他爬虫无法处理 url 中的点和“:”。所以纯 IP 地址和端口号是不允许的。
要解决此问题,您可以创建一个子域,它重定向到 Node.js 应用程序
我的子域 Apache 虚拟主机:
<VirtualHost *:80>
ServerAdmin info@example.net
ServerName prerender.example.net
ServerAlias prerender.example.net
ProxyPass / http://localhost:3000/ connectiontimeout=5 timeout=30
</VirtualHost>
连同 prerender.io 他们自己的回答,我设法让它发挥作用。
虽然代理和重定向对于社交媒体爬虫来说并不重要,因为 URL 已经粘贴在那里了。使用代理标记是一种很好的做法。
您的重写规则应该是代理,而不是重定向。重定向到您的预呈现服务器会导致各种问题,包括告诉 Google 将用户从搜索结果直接发送到您的预呈现服务器(这真的很糟糕!)。
重写规则部分应该是:
RewriteRule ^(.*)$ http://example.nl:3000/http://www.example.nl/? [P,L]