使用 caddy 搭建一个维基百科的镜像并添加广告赚钱

1次阅读

共计 2691 个字符,预计需要花费 7 分钟才能阅读完成。

安装 replace-response 模块

caddy add-package github.com/caddyserver/replace-response

Caddyfile

主站

http://zhwk.example.com {
        reverse_proxy * https://zh.wikipedia.org {header_up Host {upstream_hostport}
                header_up X-Real-IP {http.request.remote.host}
                header_up X-Forwarded-For {http.request.remote.host}
                header_up X-Forwarded-Port {http.request.port}
                header_up X-Forwarded-Proto {http.request.scheme}
                header_up Accept-Encoding identity
                header_down location (https://zh.wikipedia.org/)(.*) https://zhwk.example.com/\
                header_down location (https://zh.m.wikipedia.org/)(.*) http://mzhwk.example.com/\
        }

        replace {
                "upload.wikimedia.org" "upzhwk.example.com"
                "zh.wikipedia.org" "zhwk.example.com"
                "zh.m.wikipedia.org" "mzhwk.example.com"
                "/w/index.php?title=Special:%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95" """w/index.php?title=Special:%E5%88%9B%E5%BB%BA%E8%B4%A6%E6%88%B7" """action=edit" """" ""
        }
}

移动站

http://mzhwk.example.com {
    reverse_proxy * https://zh.m.wikipedia.org {header_up Host {upstream_hostport}
                header_up X-Real-IP {http.request.remote.host}
                header_up X-Forwarded-For {http.request.remote.host}
                header_up X-Forwarded-Port {http.request.port}
                header_up X-Forwarded-Proto {http.request.scheme}
                header_up Accept-Encoding identity
                header_down location (https://zh.wikipedia.org/)(.*) https://zhwk.example.com/\
                header_down location (https://zh.m.wikipedia.org/)(.*) http://mzhwk.example.com/\
        }

        replace {
                "upload.wikimedia.org" "upzhwk.example.com"
                "zh.wikipedia.org" "zhwk.example.com"
                "zh.m.wikipedia.org" "mzhwk.example.com"
                "/w/index.php?title=Special:%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95" """w/index.php?title=Special:%E5%88%9B%E5%BB%BA%E8%B4%A6%E6%88%B7" """action=edit" """" ""
        }
}

静态资源

http://upzhwk.example.com {
     reverse_proxy * https://upload.wikimedia.org {header_up Host {upstream_hostport}
                header_up X-Real-IP {http.request.remote.host}
                header_up X-Forwarded-For {http.request.remote.host}
                header_up X-Forwarded-Port {http.request.port}
                header_up X-Forwarded-Proto {http.request.scheme}
                header_up Accept-Encoding identity
        }
}

屏蔽了登录、注册、编辑功能,防止被恶意使用。

请将 example.com 替换成自己的域名,另外因为 cloudflare 不支持 多级子域名,所以移动站的一级子域名使用的 mzhwk。

添加广告

如果需要添加广告,请加入下面内容

"" "广告代码 "

注意事项

  • 运行的服务器必须可以访问维基百科。
  • 使用一个新的独立域名,避免造成主域名不可用。
  • 可以在 cloudflare 上开启禁止自动机器人。
  • 可以设置一个用户名和密码,限制他人访问。
  • 另外你也可以加入谷歌广告,赚回来一些服务器成本。
  • 推荐使用 cloudflare,避免服务器 ip 被墙。

推荐廉价域名后缀

  • win 4.16 美元,续费 5.16
  • uk 4.94 美元,续费 4.94
  • us 6.50 美元,续费 6.50
  • cc 8 美元,续费 8

还有一些首年 1 美元的域名后缀,不过续费有一些贵,如果做一次性域名就很划算。

我搭建的一个样例:https://zhwk.kkwiki.win/ 不过没有加广告。

你们可以按教程搭建,然后加谷歌广告赚外汇。

原文:https://blog.chenjia.info/posts/2024/08/%E4%BD%BF%E7%94%A8caddy%E6%90%AD%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%BB%B4%E5%9F%BA%E7%99%BE%E7%A7%91%E7%9A%84%E9%95%9C%E5%83%8F%E5%B9%B6%E6%B7%BB%E5%8A%A0%E5%B9%BF%E5%91%8A/

正文完
 0