8

#Ghost 如何正确添加ads.txt避免404错误?

 11 months ago
source link: https://xmanyou.com/ghost-ru-he-zheng-que-tian-jia-ads-txtbi-mian-404/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

9 June 2023 / ghost

#Ghost 如何正确添加ads.txt避免404错误?

ghost是一款开源的建站工具,与历史悠久的wordpress不同,它使用Node.js开发。wordpress经过了这么多年,已经建立了非常完善的生态系统,这是ghost做为后起之秀,相比之下最为薄弱的环节。

ads.txt是网站进行广告变现很重要的工具,它可以用来证明你对网站的所有权,只有添加到该文件中的广告账号才可以在该网站进行变现。

通常ads.txt需要添加到网站的域名根目录,比如https://xmanyou.com/ads.txt

那么,问题来了,ghost要如何添加ads.txt呢?

特别的,如果没有正确添加,ghost默认会把
https://xmanyou.com/ads.txt
重定向到
https://xmanyou.com/ads.txt/
从而出现404错误。

方法1. 使用nginx等自行解析ads.txt

如果你使用nginx作为ghost的网关,那么,你可以在nginx里自己添加一条ads.txt的解析。

例如:假设你的ads.txt文件存放在/var/www/html/ads.txt,那么

    location ~ ^/(ads.txt) {
        add_header Content-Type text/plain;
        root /var/www/html;
    }

方案2. 使用ghost解析ads.txt

其实,ghost官方也支持静态文件解析,默认的路径是当前主题所在的目录,所以只需要将ads.txt添加到主题包里,然后重新激活就可以了。

具体步骤如下:

  • 1). 下载当前所用的主题zip包
  • 2). 解压,并添加ads.txt到解压后的主题目录
  • 3). 重新打包主题zip包
  • 4). 上传添加了ads.txt的主题包
  • 5). 激活该主题

这样就完成了。

同样的,利用该方法,还可以让ghost解析别的静态文件,比如app-ads.txt等。

阿斌

Read more posts by this author.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK