部署prerender服务器
// 安装 git
sudo apt-get install git
sudo apt-get install curl // 请先确认服务器是否安装了curl 如果已经安装跳过即可
// 安装 node
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential
// 下载 prerender
git clone https://github.com/prerender/prerender
cd prerender
// 安装依赖包
npm i --registry https://registry.npm.taobao.org
// 启动
node server.js
// 如果遇到以下错误(后面两行提示的)
2016-12-31T19:57:42.231Z starting worker thread #0
2016-12-31T19:57:42.452Z starting phantom...
2016-12-31T19:57:42.460Z Server running on port 3000
/home/ubuntu/prerender/node_modules/.2.1.14@phantomjs-prebuilt/lib/phantom/bin/phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory
(node:10992) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: /home/ubuntu/prerender/node_modules/.2.1.14@phantomjs-prebuilt/lib/phantom/bin/phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory
// 修复方案
sudo apt-get install libfontconfig
// 启动成功
ubuntu@VM-0-110-ubuntu:~/prerender$ node server.js
2016-12-31T20:00:55.655Z starting worker thread #0
2016-12-31T20:00:55.865Z starting phantom...
2016-12-31T20:00:55.873Z Server running on port 3000
2016-12-31T20:00:56.491Z started phantom
问题:
1、需要安装chrome。如何安装可以百度或google
2、可能需要增加chrome的启动选项在server.js里
var server = prerender({
chromeFlags: ['--no-sandbox', '--headless', '--disable-gpu', '--remote-debugging-port=9222', '--hide-scrollbars']
});
3、修改启动端口,在启动服务器前设置环境变量,export PORT=3300 或
var server = prerender({
port: 3300
});