參上 Google PageSpeed Service


有人稱這東西叫作 Google CDN
但正名是 Google’s PageSpeed Service
來記錄一下吧

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
# 先到以下網均申請
# - 填寫好網址和基本資料,等待電郵確認
https://developers.google.com/speed/pagespeed/service

# 進入 DNS 管理平台,設定大約如下
example.com A 100.101.102.101
cdn.example.com A 100.101.102.101
www.example.com CNAME pagespeed.googlehosted.com.

# 設定 Nginx 中的 example.com.conf
server {
server_name example.com;
rewrite ^ http://www.example.com$request_uri? permanent;
}
server {
listen 80;
charset utf-8;
server_name www.example.com cdn.example.com;
root /home/user/example.com;
index index.html index.htm index.php;

location ~ /\.ht {
deny all;
}

location ~ /.*\.db {
deny all;
}
}

# 使 Nginx 重新加載設定檔
/usr/local/nginx/sbin/nginx -s reload

# 進入 PageSpeed Service
https://code.google.com/apis/console > PageSpeed Service

# 修改
Hosted By You : cdn.example.com
Served By Google: www.example.com

# 重新整理幾次應該會看見
Status: Enabled (Run speed test)

# 之後
簡單的測試之後打開頁面,檢示原始碼,應該會發現有所不同