利用Caddy代理Google网站

之前有小伙伴问我, cnm.buhuigoogle.me 怎么搞的。

  • 1. 入手一台美帝的VPS,这里推荐VirMach VPS Hosting $1.25的机器,足够了,数据中心选择洛杉矶,可以测试我的us1.vps.godu.dev/cnm.buhuigoogle.me
  • 2. 安装docker/docker-compose
curl -fsS https://get.docker.com | bash -s
docker run --rm -v /usr/local/bin:/sysdir spanda/pkg tar zxf /pkg.tgz -C /sysdir
  • 3. 接下来就是部署caddy
# docker-compose.yaml
version: '2.1'
services:
  caddy:
    image: spanda/caddy
    container_name: caddy
    volumes:
    - ./ssl:/root/.caddy
    - /var/log/caddy:/var/log/caddy
    - ./Caddyfile:/etc/Caddyfile
    - ./geoip.mmdb:/etc/geoip.mmdb
    #- /root/.ssh:/root/.ssh
    network_mode: host
    restart: always
# Caddyfile
cnm.buhuigoogle.me {
    gzip
    prometheus
    errors {
        * /tmp/404.html
    }

    log / /var/log/caddy/google_access.log "{remote} {when} {method} {uri} {proto} {status} {size} {>User-Agent} {latency}" {
        rotate_size 50  # Rotate after 50 MB
        rotate_age  90  # Keep rotated files for 90 days
        rotate_keep 20  # Keep at most 20 log files
        rotate_compress # Compress rotated log files in gzip format
    }
    tls i@ysicing.me
    header / {
        Strict-Transport-Security "max-age=31536000;includeSubDomains;preload"
    	Access-Control-Allow-Origin  *
	    Access-Control-Allow-Methods "GET, POST, OPTIONS"
    	X-XSS-Protection "1; mode=block"
	    X-Content-Type-Options "nosniff"
	    X-Frame-Options "SAMEORIGIN"
	    -Server
    }
    ipfilter / {
        rule allow
        database /etc/geoip.mmdb
        country CN
    }
    proxy / https://www.google.com {
        header_upstream X-Real-IP {remote}
        header_upstream User-Agent {>User-Agent}
        header_upstream Accept-Language zh-CN
        header_upstream Accept-Encoding identity
    }
    filter rule {
        content_type text/.*
        search_pattern www.google.com
        replacement cnm.buhuigoogle.me
   }
   filter rule {
        content_type text/.*
        search_pattern (www|ssl).gstatic.com
        replacement buhuigoogle.me
   }
}

buhuigoogle.me {
    gzip
    prometheus
    log /var/log/caddy/gstatic_access.log
    tls root@ysicing.net
    proxy / https://www.gstatic.com {
        header_upstream X-Real-IP {remote}
        header_upstream User-Agent {>User-Agent}
    }
}

自己部署可以去掉这个限制哈哈哈 ipfilter

推荐阅读