leadscloud

Google SEO|外贸营销推广

关于Memcached系统

Memcached是一个自由开源的,高性能,分布式内存对象缓存系统。Memcached是以LiveJournal旗下Danga Interactive公司的Brad Fitzpatric为首开发的一款软件。现在已成为mixi、hatena、Facebook、Vox、LiveJournal等众多服务中提高Web应用扩展性的重要因素。Memcached是一种基于内存的key-value存储,用来存储小块的任意数据(字符串、对象)。这些数据可以是数据库调用、API调用或者是页面渲染的结果。Memcached简洁而强大。它的简洁设计便于快速开发,减轻开发难度,解决了大数据量缓存的很多问题。它的API兼容大部分流行的开发语言。本质上,它是一个简洁的key-value存储系统。一般的使用目的是,通过缓存数据库查询结果,减少数据库访问次数,以提高动态Web应用的速度、提高可扩展性。

关于分布式DDoS原理

分布式拒绝服务(DDoS:Distributed Denial of Service)攻击指借助于客户/服务器技术,将多个计算机联合起来作为攻击平台,对一个或多个目标发动DDoS攻击,从而成倍地提高拒绝服务攻击的威力。通常,攻击者使用一个偷窃帐号将DDoS主控程序安装在一个计算机上,在一个设定的时间主控程序将与大量代理程序通讯,代理程序已经被安装在网络上的许多计算机上。代理程序收到指令时就发动攻击。利用客户/服务器技术,主控程序能在几秒钟内激活成百上千次代理程序的运行。

关于反射式DRDoS原理

DRDoS是英文“Distributed Reflection Denial of Service ”的缩写,中文意思是“分布式反射拒绝服务”。与DoS、DDoS不同,该方式靠的是发送大量带有被害者IP地址的数据包给攻击主机,然后攻击主机对IP地址源做出大量回应,形成拒绝服务攻击。

LNMP修复办法

以下是lnmp一键安装脚本的修复方法

根据阿里的建议:

如果您的Memcached版本低于1.5.6,且不需要监听UDP。您可以重新启动Memcached 加入 -U 0启动参数,例如:Memcached -U 0,禁止监听在udp协议上

vi /etc/init.d/memcached

1
2
3
4
5
6
7
8
start () {
echo -n $"Starting $prog: "
memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -P /var/run/memcached.pid $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}

改为(启动项添加 -U 0)

1
2
3
4
5
6
7
start () {
echo -n $"Starting $prog: "
memcached -d -p $PORT -u $USER -m $CACHESIZE -c $MAXCONN -U 0 -P /var/run/memcached.pid $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/memcached
}

参考资料

基于Memcached分布式系统DRDoS拒绝服务攻击技术研究
https://paper.seebug.org/535/

绝对路径

当Hexo项目中只用到少量图片时,可以将图片统一放在source/images文件夹中,通过markdown语法访问它们。

source/images/image.jpg

1
![](/images/image.jpg)

图片既可以在首页内容中访问到,也可以在文章正文中访问到。

相对路径

图片除了可以放在统一的images文件夹中,还可以放在文章自己的目录中。文章的目录可以通过配置_config.yml来生成。

_config.yml

1
post_asset_folder: true

_config.yml文件中的配置项post_asset_folder设为true后,执行命令$ hexo new post_name,在source/_posts中会生成文章post_name.md和同名文件夹post_name。将图片资源放在post_name中,文章就可以使用相对路径引用图片资源了。

_posts/post_name/image.jpg

1
![](image.jpg)

上述是markdown的引用方式,图片只能在文章中显示,但无法在首页中正常显示。

如果希望图片在文章和首页中同时显示,可以使用标签插件语法。

_posts/post_name/image.jpg

1
{% asset_img image.jpg This is an image %}

Github上面的一个项目 Nginx Module for Google ,可以实现快捷部署Google镜像。

重新编绎Nginx

1
2
3
4
5
[root@AY1407181147267575e9Z ~]# nginx -V
nginx version: nginx/1.6.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6

我使用的是lnmp.org的一键安装包,其它情形查看 https://github.com/cuber/ngx_http_google_filter_module ,上面有详细的说明。

1
2
3
4
5
6
7
8
9
10
11
12
git clone https://github.com/cuber/ngx_http_google_filter_module
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
cd nginx-1.6.0/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module \
--with-http_ssl_module --with-http_gzip_static_module --with-ipv6 \
--add-module=../ngx_http_google_filter_module \
--add-module=../ngx_http_substitutions_filter_module

make && make install
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
nginx -t
service nginx restart

虚拟主机配置

vi /usr/local/nginx/conf/vhost/demo.website.com.conf, 保持内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# https的可以使用lnmp的脚本配置,在添加虚拟主机的时候有提示是否使用ssl
server {
listen 443 ssl http2;
server_name demo.website.com;
ssl_certificate /usr/local/nginx/conf/ssl/demo.website.com.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/demo.website.com.key;
ssl_session_timeout 10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers CHACHA20:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RC4-SHA:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!DSS:!PKS;
ssl_session_cache builtin:1000 shared:SSL:10m;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
location / {
google on;
google_scholar on; # google_scholar 依赖于 google, 所以 google_scholar 无法独立使用。由于谷歌学术近日升级, 强制使用 https 协议, 并且 ncr 已经支持, 所以不再需要指定谷歌学术的 tld
google_language en; # 语言偏好,默认使用 zh-CN (中文)
}
}
server {
listen 80;
server_name demo.website.com;
rewrite ^(.*)$ https://$host$1 permanent; # 访问http跳转至https
}

保存配置文件,重启nginx即可。

参考资料

Nginx Module for Google

昨天把个人博客迁移到github pages上面了,今天把博客主题重新整理了下。

这个博客从10年到今年,有8年时间了,最近一年因为域名过期,一直也没有整理它,今天把它弄好了,过几天再把之前的域名申请好,然后就可以上线了,未来准备换个域名,时间久了,人也变化很多,等这个域名的权重转移好之后,就可以更换了。

此博客重新上线,放到了github.com上面一份,VPS上面一份,使用了travis自动发布,由于国内域名需要备案,要在国内畅通打开还需要一段时间。

博客涉及到诸多技术问题,有想了解的,可以到我的github页面去查看源码,不是特别难,但第一次部署比较麻烦。

博客添加RSS功能

安装RSS插件

npm install hexo-generator-feed --save

开启网站 RSS 支持

编辑网站根目录下的 _config.yml,添加以下代码开启

1
2
3
4
5
6
7
8
9
# RSS订阅支持
plugin:
- hexo-generator-feed

# Feed Atom
feed:
type: atom
path: atom.xml
limit: 20

主题开启 RSS 支持

主题不同开启方法不同,我的是 NexT 主题,默认就可以;其他主题请参考主题说明。

生成 RSS

执行 hexo clean && hexo g重新生成博客文件完成部署即可。 转载请注明出处,本文采用 CC4.0 协议授权

头像生成地址

https://faceyourmanga.com

参考资料

https://reuixiy.github.io/technology/computer/computer-aided-art/2017/06/09/hexo-next-optimization.html
https://github.com/willin/hexo-wordcount
体验GitHub Issues的评论系统——Gitment
https://github.com/iissnan/hexo-theme-next
http://saili.science/2017/04/02/github-for-win/

使用 TRAVIS 自动部署 HEXO 到 GITHUB 与 自己的服务器

前期准备

请尽可能用比较新的 RubyGems 版本,建议 2.6.x 以上。

1
2
3
$ gem update --system # 这里请翻墙一下
$ gem -v
2.6.3

使用国内镜像

1
2
3
4
$ gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
$ gem sources -l
https://gems.ruby-china.org
# 确保只有 gems.ruby-china.org

参考: https://gems.ruby-china.org/

安装travis

sudo gem install travis

配置github

我的github之前已经配置好GitHub Pages,现在需要变成下面这样,之前只有master一个分支。

  • master 存放 Hexo 生成好的静态文件,所有 commit 信息格式均为 Site updated: %Y-%m-%d %H:%M:%S
  • source 存放 scaffolds(脚手架)、source(文章 Markdown 源码)、_config.yml(Hexo 配置)等文件,并设置为 repo 的默认分支。

配置 Travis CI

  • 使用github帐号登录Travis,右上方按钮点击同步项目,下方打开需要集成的项目,最后点击齿轮进入项目配置页面
  • 打开Build only if .travis.yml is present

参考这篇文章 https://segmentfault.com/a/1190000009054888

通过命令行登录 Travis 并加密文件:

在hexo blog项目根目录下创建一个文件 .travis.yml

1
2
3
4
5
cd 博客根目录
touch .travis.yml

#创建一个文件夹.travis
mkdir .travis

生成一个 ssh 密钥对(不要嫌麻烦直接把你机器上的秘钥拿去用了,太危险):

1
2
3
4
cd 博客根目录
cd .travis/
# 会生成traivs.key 和travis.key.pub
$ ssh-keygen -f travis.key

然后把生成的公钥文件(e.g. travis.key.pub)分别添加到 GitHub Deploy Keys、VPS 上的 ~/.ssh/authorized_keys 中,这样 Travis CI 的机器就可以直接访问这些服务器了。

1
2
3
4
5
6
7
8
cd 博客根目录
cd .travis/
# 交互式操作,使用 GitHub 账号密码登录
# 如果是私有项目要加个 --pro 参数
$ travis login --auto
# 加密完成后会在当前目录下生成一个 travis.key.enc 文件
# 还会在你的 .travis.yml 文件里自动加上用于解密的 shell 语句
$ travis encrypt-file travis.key -add

以上步骤完成后你会得到一个 travis.key.enc

编辑 .travis.yml

1
2
cd 博客根目录
vi .travis.yml

这是我的配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
language: node_js
node_js: stable

# 只监听 source 分支的改动
branches:
only:
- source

# 缓存依赖,节省持续集成时间
cache:
yarn: true
directories:
- node_modules
# - themes

before_install:
# 解密 RSA 私钥并设置为本机 ssh 私钥
- openssl aes-256-cbc -K $encrypted_9aab6d74e2ca_key -iv $encrypted_9aab6d74e2ca_iv
-in .travis/travis.key.enc -out ~/.ssh/id_rsa -d
- chmod 600 ~/.ssh/id_rsa
# 修改本机 ssh 配置,防止秘钥认证过程影响自动部署
#- mv -fv .travis/ssh-config ~/.ssh/config #这一步不需要,如果添加了ssh_know_hosts
- git config --global user.name "leadscloud"
- git config --global user.email "sbmzhcn@gmail.com"
# 赋予自动部署脚本可执行权限
- chmod +x .travis/deploy.sh

install:
# 安装 Hexo 及其依赖
- yarn
# 当 Travis 文件缓存不存在时,从 Gitee 私有仓库 clone 主题
#- if [ ! -d "themes/next" ]; then git clone git@github.com:leadscloud/hexo-theme-next.git themes/next; fi

script:
# 生成静态页面
- node_modules/.bin/hexo clean
- node_modules/.bin/hexo generate

after_success:
# 部署到 GitHub Pages 和 VPS
- .travis/deploy.sh

addons:
ssh_know_hosts:
- github.com
- love4026.org

vi .travis/deploy.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/bin/bash
set -ev
export TZ='Asia/Shanghai'

# 使用 rsync同步到 VPS
rsync -rv --delete -e 'ssh -o stricthostkeychecking=no -p 22' public/ root@182.92.100.67:/home/wwwroot/love4026.org

# 先 clone 再 commit,避免直接 force commit
git clone -b master git@github.com:leadscloud/leadscloud.github.io.git .deploy_git

cd .deploy_git
git checkout master
mv .git/ ../public/
cd ../public

git add .
git commit -m "Site updated: `date +"%Y-%m-%d %H:%M:%S"`"

# 同时 push 一份到自己的服务器上
#git remote add vps git@love4026.org:hexo.git

#git push vps master:master --force --quiet
git push origin master:master --force --quiet

删除一些文件

1
2
3
cd 博客根目录/.travis/
rm travis.key
rm travis.key.pub

由于我之前有github pages内容了,我需要把之前的内容与现有的hexo博客内容合并下

1
2
3
4
git init
git remote add origin git@github.com:leadscloud/leadscloud.github.io.git
git fetch origin master:temp
git merge temp

编辑下.gitignore 忽略一些文件

1
2
3
4
5
6
7
8
9
10
.DS_Store
Thumbs.db
db.json
*.log
node_modules/
public/
.deploy*/
package-lock.json
wordpress.xml
public/

最终测试

每次 push 新 commit 到 source 分支后,Travis CI 就会自动帮你构建最新的静态博客,并部署至 Github Pages 和你自己的 VPS 上。

1
2
3
4
git checkout --orphan source
git add .
git commit -m "Travis CI"
git push origin source:source

关于 –orphan 请参考 如何建立一个没有 Parent 的独立 Git branch

我的博客项目配置文件

https://github.com/leadscloud/leadscloud.github.io/tree/source

参考链接

使用 Travis CI 自动部署 Hexo 博客
使用 Travis 自动部署 Hexo 到 Github 与 自己的服务器
优化Hexo博客 - 压缩 HTML、CSS、JS、IMG 等

中继的原因是因为一些ip在我们本地的电脑上是无法连通的,但在阿里云等其它VPS上面就可以访问,这样我们可能通过中继来继续使用我们的shadowsocks.

开启系统的转发功能

vi /etc/sysctl.conf

net.ipv4.ip_forward=0 ,修改成 net.ipv4.ip_forward=1

编辑后使用以下命令让配置马上生效

sysctl -p

iptables的命令

1
2
3
4
iptables -t nat -A PREROUTING -p tcp --dport [端口号] -j DNAT --to-destination [目标IP]
iptables -t nat -A PREROUTING -p udp --dport [端口号] -j DNAT --to-destination [目标IP]
iptables -t nat -A POSTROUTING -p tcp -d [目标IP] --dport [端口号] -j SNAT --to-source [本地服务器公网IP]
iptables -t nat -A POSTROUTING -p udp -d [目标IP] --dport [端口号] -j SNAT --to-source [本地服务器公网IP]

重启iptables使配置生效

1
2
service iptables save
service iptables restart

直接修改iptables文件

上面添加过后,未来再修改ip的话,可以直接修改文件/etc/sysconfig/iptables

1
vi /etc/sysconfig/iptables

:%s/1.1.1.1/2.2.2.2 可以替换ip地址

然后

1
service iptables restart

Linode CentOS7下面的安装流程

安装前准备

1
2
3
yum install git -y
yum install epel-release -y
yum install libsodium -y # 使用salsa20 或 chacha20 或 chacha20-ietf 算法必须的

下载shadowsocksr

1
git clone -b manyuser https://github.com/shadowsocksr-backup/shadowsocksr.git && cd shadowsocksr/

配置shadowoskcr

vi user-config.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
"server": "0.0.0.0",
"server_ipv6": "::",
"server_port": 3008,
"local_address": "127.0.0.1",
"local_port": 1080,

"password": "password-lanthy.com",
"method": "chacha20",
"protocol": "auth_aes128_md5",
"protocol_param": "",
"obfs": "tls1.2_ticket_auth_compatible",
"obfs_param": "",
"speed_limit_per_con": 0,
"speed_limit_per_user": 0,

"additional_ports" : {}, // only works under multi-user mode
"additional_ports_only" : false, // only works under multi-user mode
"timeout": 120,
"udp_timeout": 60,
"dns_ipv6": false,
"connect_verbose_info": 0,
"redirect": "",
"fast_open": true
}

后台运行ssr

cd shadowsocks

后台运行

python server.py -d start

如果要停止/重启:

python server.py -d stop/restart

查看日志:

tail -f /var/log/shadowsocksr.log

SSR启动脚本

以下启动脚本均假定shadowsocks-rss安装于/root/shadowsocksr目录,配置文件为/root/shadowsocksr/user-config.json,请按照实际情况自行修改

SysVinit启动脚本,适合CentOS/RHEL6系以及Ubuntu 14.x,Debian7.x

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/sh
# chkconfig: 2345 90 10
# description: Start or stop the Shadowsocks R server
#
### BEGIN INIT INFO
# Provides: Shadowsocks-R
# Required-Start: $network $syslog
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Start or stop the Shadowsocks R server
### END INIT INFO

# Author: Yvonne Lu(Min) <min@utbhost.com>

name=shadowsocks
PY=/usr/bin/python
SS=/root/shadowsocksr/shadowsocks/server.py
SSPY=server.py
conf=/root/shadowsocksr/user-config.json

start(){
$PY $SS -c $conf -d start
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name start success"
else
echo "$name start failed"
fi
}

stop(){
pid=`ps -ef | grep -v grep | grep -v ps | grep -i "${SSPY}" | awk '{print $2}'`
if [ ! -z "$pid" ]; then
$PY $SS -c $conf -d stop
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name stop success"
else
echo "$name stop failed"
fi
else
echo "$name is not running"
RETVAL=1
fi
}

status(){
pid=`ps -ef | grep -v grep | grep -v ps | grep -i "${SSPY}" | awk '{print $2}'`
if [ -z "$pid" ]; then
echo "$name is not running"
RETVAL=1
else
echo "$name is running with PID $pid"
RETVAL=0
fi
}

case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
'restart')
stop
start
RETVAL=$?
;;
*)
echo "Usage: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL

请将上述脚本保存为 /etc/init.d/shadowsocks

CentOS/RHEL6 执行:

1
chmod 755 /etc/init.d/shadowsocks && chkconfig --add shadowsocks && service shadowsocks start

Ubuntu 14.x,Debian7.x 执行:

1
chmod 755 /etc/init.d/shadowsocks ; update-rc.d shadowsocks defaults ; service shadowsocks start

systemd脚本

systemd脚本,适用于CentOS/RHEL7以上,Ubuntu 15以上,Debian8以上

单用户版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[Unit]
Description=ShadowsocksR server
After=network.target
Wants=network.target

[Service]
Type=forking
PIDFile=/var/run/shadowsocksr.pid
ExecStart=/usr/bin/python /usr/local/shadowsocksr/shadowsocks/server.py --pid-file /var/run/shadowsocksr.pid -c /usr/local/shadowsocksr/user-config.json -d start
ExecStop=/usr/bin/python /usr/local/shadowsocksr/shadowsocks/server.py --pid-file /var/run/shadowsocksr.pid -c /usr/local/shadowsocksr/user-config.json -d stop
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always

[Install]
WantedBy=multi-user.target

多用户版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[Unit]
Description=ShadowsocksR server
After=syslog.target
After=network.target

[Service]
LimitCORE=infinity
LimitNOFILE=512000
LimitNPROC=512000
Type=simple
WorkingDirectory=/usr/local/shadowsocksr
ExecStart=/usr/bin/python /usr/local/shadowsocksr/server.py
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
Restart=always

[Install]
WantedBy=multi-user.target

请将上述脚本保存为 /etc/systemd/system/shadowsocksr.service
并执行systemctl enable shadowsocksr.service && systemctl start shadowsocksr.service

参考资料

SSR 优化

shadowsocks SSR客户端下载

参考资料

Nginx服务器,可以安装ngx_pagespeed扩展,这样你的服务器下面的网站就可以自动通过pagespeed优化。网站返回的源码数据是经过pagespeed处理过的,比如处自动压缩css、html、javascript,图片自动压缩及处理为更小的格式webp。

同时包含一些最佳实践:

  • 优化缓存——整合应用程序的数据和逻辑
  • 最小化round-trip次数——削减连续的请求/响应周期数
  • 最小化请求开销——削减上传大小
  • 最小化负载大小——削减响应、下载及缓存页面大小
  • 优化浏览器渲染——改善浏览器页面布局
  • 移动方面的优化——优化站点移动网络和设备方面的相关特性

网站配置

你可以在nginx.conf中全局配置,也可以针对某个网站进行配置,放在虚拟主机配置server中

1
2
3
4
5
6
7
8
9
10
11
12
server
{
listen 80 default_server;
server_name _;
#listen [::]:80;
#server_name *.org *.in;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/youwebsite;

# 从这儿开始添加, 下面的代码放在这儿

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
pagespeed on;

# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;

pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters local_storage_cache;
pagespeed EnableFilters collapse_whitespace,remove_comments;
pagespeed EnableFilters outline_css;
pagespeed EnableFilters flatten_css_imports;
pagespeed EnableFilters move_css_above_scripts;
pagespeed EnableFilters move_css_to_head;
pagespeed EnableFilters outline_javascript;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters rewrite_javascript;
pagespeed EnableFilters rewrite_css,sprite_images;
pagespeed EnableFilters rewrite_style_attributes;
pagespeed EnableFilters recompress_images;
pagespeed EnableFilters resize_images;
pagespeed EnableFilters convert_meta_tags;

# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }

安装过程

1
2
3
4
5
6
7
8
9
10
11
12
#[check the release notes for the latest version]
NPS_VERSION=1.12.34.3-stable
cd
wget https://github.com/pagespeed/ngx_pagespeed/archive/v${NPS_VERSION}.zip
unzip v${NPS_VERSION}.zip
cd ngx_pagespeed-${NPS_VERSION}/
NPS_RELEASE_NUMBER=${NPS_VERSION/beta/}
NPS_RELEASE_NUMBER=${NPS_VERSION/stable/}
psol_url=https://dl.google.com/dl/page-speed/psol/${NPS_RELEASE_NUMBER}.tar.gz
[ -e scripts/format_binary_url.sh ] && psol_url=$(scripts/format_binary_url.sh PSOL_BINARY_URL)
wget ${psol_url}
tar -xzvf $(basename ${psol_url}) # extracts to psol/

修改lnmp include/upgrade_nginx.sh 文件

添加 --add-module=$HOME/ngx_pagespeed-${NPS_VERSION} ${PS_NGX_EXTRA_FLAGS}

参考资料

Google: Build ngx_pagespeed From Source
Github: Automatic PageSpeed optimization module for Nginx

其它一些国内外的数据报告网站,涵盖了较多行业、对了解一些行业的国际市场具有较大的帮助

一些行业报告网站

艾瑞咨询:http://www.iresearch.cn/
艾司隆:https://www.epsilon.com
CTR洞察中国:http://www.ctrchina.cn/
罗兰贝格:https://www.rolandberger.com
英敏特:http://china.mintel.com
麦肯锡:http://www.mckinsey.com.cn/
德勤中国:https://www2.deloitte.com/cn/zh.html
尼尔森中国:http://www.nielsen.com/cn/zh/insights.html?pageNum=1
华通明略:http://www.millwardbrown.com/subsites/china/home
波士顿咨询:https://www.bcg.com/zh-cn/default.aspx
埃森哲:https://www.accenture.com/cn-zh/new-applied-now
清科研究中心:http://report.pedata.cn/
贝恩:http://www.bain.cn/news.php
尼尔森网联:http://www.nielsenccdata.com/
普华永道:https://www.pwccn.com/zh
贝莱德:https://www.blackrock.com/cn
艾媒咨询:http://www.iimedia.cn/
IBM:https://www.ibm.com/cn-zh/
埃维诺:https://www.avanade.com/zh-cn
威勃庞尔:http://www.webpowerchina.com/
实力传播:http://socialbeta.com/t/company-agency-zenithoptimedia
iClick爱点击:http://www.i-click.com/zh/
Criteo:http://www.criteo.com/cn/resources/
百分点:http://www.baifendian.com/reports/
Trustdata:http://www.itrustdata.cn/
友盟:http://www.umeng.com/reports.html?from=hp
微博电视指数:http://tv.weibo.com/zhishu
星图数据:http://www.syntun.com.cn/datanews/hotspot.html
DCCI:http://www.dcci.com.cn/
知微数据:http://www.weiboreach.com/
胖鲸智酷:https://socialone.com.cn
秒针系统:http://www.miaozhen.com/
明思力中国:http://mslgroup.cn/cn/insights/
阿里研究院:http://www.aliresearch.com/blog/index/lists/tag/3827.html
百度营销研究院:http://bim.baidu.com/ir_main.php
DataEye : https://www.dataeye.com/report
易观智库:https://www.analysys.cn/college/
艺恩网:http://www.entgroup.cn/
Quest Mobile:http://www.questmobile.com.cn/blog.html
百度MOTA:http://mota.baidu.com/index.php/
中国行业报告研究中心:http://www.reportrc.com/index.html
今日报告网:http://www.imxdata.com/
Cheetah : http://lab.cmcm.com/sjfx/
BGC: https://www.bcg.com/zh-cn/default.aspx
腾讯的企鹅智库:http://re.qq.com/
阿里研究院:http://www.aliresearch.com/
CBNData:http://cbndata.com/home
360营销研究院:http://yingxiao.360.cn/

非www到 www 的规则

1
2
3
4
5
6
7
8
if ($request_uri ~ ^(.*/)index.html$) {
return 301 $1;
}
# non-www to www
if ($host !~* ^www\.){
rewrite ^(.*)$ $scheme://www.$host$1 permanent;
}

http 到 https 的

1
2
3
4
# http to https
if ( $scheme = http ){
return 301 https://$server_name$request_uri;
}

使用了cloudflare的https重定向设置

如果使用了cloudflare,http 到https的转向需要到cloudflare上面设置

How do I redirect all visitors to HTTPS/SSL?

20180307更新

添加两个page rules 301规则也行,之前的always https没这个选项了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
curl -X POST "https://api.cloudflare.com/client/v4/zones/<zone_id>/pagerules" \
-H "X-Auth-Email: <email>" \
-H "X-Auth-Key: <api_key>" \
-H "Content-Type: application/json" \
--data '{"targets":[{"target":"url","constraint":{"operator":"matches","value":"http://love4026.org/*"}}],"actions":[{"id":"forwarding_url","value":{"url": "https://www.love4026.org/$1", "status_code": 301}}],"priority":1,"status":"active"}'

curl -X POST "https://api.cloudflare.com/client/v4/zones/<zone_id>/pagerules" \
-H "X-Auth-Email: <email>" \
-H "X-Auth-Key: <api_key>" \
-H "Content-Type: application/json" \
--data '{"targets":[{"target":"url","constraint":{"operator":"matches","value":"http://www.love4026.org/*"}}],"actions":[{"id":"forwarding_url","value":{"url": "https://www.love4026.org/$1", "status_code": 301}}],"priority":1,"status":"active"}'

curl -X POST "https://api.cloudflare.com/client/v4/zones/<zone_id>/pagerules" \
-H "X-Auth-Email: <email>" \
-H "X-Auth-Key: <api_key>" \
-H "Content-Type: application/json" \
--data '{"targets":[{"target":"url","constraint":{"operator":"matches","value":"https://love4026.org/*"}}],"actions":[{"id":"forwarding_url","value":{"url": "https://www.love4026.org/$1", "status_code": 301}}],"priority":1,"status":"active"}'

设置好后使用

1
curl -I http://love4026.org

看下结果即可

1
2
3
4
5
6
7
8
9
[root@centos-1gb-nyc3-01 ~]# curl -I http://love4026.org
HTTP/1.1 301 Moved Permanently
Date: Wed, 07 Mar 2018 02:14:15 GMT
Connection: keep-alive
Cache-Control: max-age=3600
Expires: Wed, 07 Mar 2018 03:14:15 GMT
Location: https://www.love4026.org/
Server: cloudflare
CF-RAY: 3f798c2c75a346f8-EWR
0%