加入Adsense以赚取而外的收入,结果以每日浏览人数来看,我明白单靠广告维持整个网站的运营应该是不可能的;打从本站在WordPress时就已经加入Adsense了,而本站已经尽量做到不影响阅读体验以及网站的速度。
Adsense为了验证域名以及网站的持有者的身份,Google Adsense会要求站长将 ads.txt
放到网站的根目录。
使用Digital Ocean一键脚本安装,另外我的优惠连接 https://m.do.co/c/1b223479fa8c 注册,就可享有 USD100 块钱的 Digital Ocean 账号余额。可参考《Ghost - DigitalOcean - 安装篇》
目前在Ghost部落格有两个方法:
- 将
ads.txt
直接放入主题的根目录。 - 将
ads.txt
放入Ghost的目录。
1. 将 ads.txt直接放入主题的根目录
这是最简单的方法,因为我们在上传主题时可以将 ads.txt
放入主题压缩包中,再不然就是将透过Filezilla将 ads.txt
上传到主题里。
但缺点也显而易见,每当你更换主题时都得 ads.txt
放入新主题中。
例子: /var/www/ghost/content/themes/ “你的主题”

/var/www/ghost/content/themes/ “你的主题”
2.将 ads.txt 放入Ghost的目录
比较起上一个方法,将ads.txt放入目录中步骤会比较多,但它并不会因为更换主题就得再将 ads.txt
放到主题目录中。
可以是用任何SSH终端连接修改 /etc/nginx/sites-enabled
里的 *.conf
添加 location ~ ^/ads.txt { root /var/www;}
,建议连ssl.conf也一并修改。
步骤:
到/etc/nginx/sites-enabled
cd /etc/mginx/sites-enabled
列出文件夹中的所有文件
ls
使用 nano
指令修改 .conf
文档。
nano everblogger.cc.conf
完成后 ctrl + x
退出 Enter
储存皆可。
参考我的范本:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name everblogger.cc;
root /var/www/ghost/system/nginx-root; # Used for acme.sh SSL verification (https://acme.sh)
ssl_certificate /etc/letsencrypt/everblogger.cc/fullchain.cer;
ssl_certificate_key /etc/letsencrypt/everblogger.cc/everblogger.cc.key;
include /etc/nginx/snippets/ssl-params.conf;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
location ~ ^/ads.txt {
root /var/www;
}
location ~ /.well-known {
allow all;
}a
client_max_body_size 50m;
}
重启Ngnix
sudo systemctl reload nginx
验证
因为浏览者都有缓存cache 要马上验证ads.txt的话推荐使用另一款浏览器的无痕模式浏览 https://everblogger.cc/ads.txt
(可将everblogger.cc更改为你的网站),https://everblogger.cc/ads.txt
总结
Ghost在网络上的中文教程并不算多,网络上的教程大部分都是英文教程,希望我所写的文章能帮助那些想使用Ghost的朋友。
参考:
