├── .gitignore ├── README.md └── assets ├── image-20230905150832916.png ├── image-20230905151501383.png └── image-20230905151619657.png /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | # local env files 5 | .env.local 6 | .env.*.local 7 | 8 | # Log files 9 | npm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | 13 | # Editor directories and files 14 | .idea 15 | .vscode 16 | *.suo 17 | *.ntvs* 18 | *.njsproj 19 | *.sln 20 | *.sw? 21 | 22 | #Electron-builder output 23 | /dist_electron 24 | package-lock.json 25 | yarn.lock 26 | /data/dist 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 谷歌翻译三方代理搭建 2 | 3 | > 注意: 前提是必须拥有自己的域名, 没有的话下面的步骤是无法进行下去的!!! 4 | 5 | 🚨**温馨提示:现在联通网络可能会拦截 Vercel 部署的站点!** 6 | 7 | ## 使用 Vercel 搭建免费代理 8 | 9 | > 部署方式其实很简单,大致步骤如下,如果在某个步骤无法继续随便百度搜索下就能解决,很简单! 10 | 11 | 1. 需要在本机上安装 `Vercel` 12 | 13 | ```bash 14 | npm i -g vercel 15 | ``` 16 | 17 | 2. 安装号以后,使用 `vsercel login` 命令进行登录,登录过程中根据提示操作即可. 18 | 19 | 3. 登录成功以后,新建一个 `json` 文件,里面内容如下: 20 | 21 | ```json 22 | { 23 | "version": 2, 24 | "routes": [ 25 | { 26 | "src": "/(.*)", 27 | "dest": "https://translate.google.com/$1", 28 | "headers": { 29 | "Cache-Control": "no-cache", 30 | "Host": "translate.google.com", 31 | "origin": "https://translate.google.com", 32 | "referer": "https://translate.google.com/", 33 | "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36" 34 | } 35 | } 36 | ] 37 | } 38 | ``` 39 | 40 | 4. 然后再这个`json`文件所在的目录打开终端(路径中最好不要有中文),执行以下命令,比如我命名的`json`文件名字是`google_translate.json`,那么对应的执行命令如下: 41 | 42 | ```bash 43 | verceL -A ./google_translate.json --prod 44 | ``` 45 | 46 | 5. 执行后就开始部署了,根据提示进行相关选择配置接口.部署成功后,控制台会给你一个默认的域名,这个域名打开就能看到你代理的网站了。同时在`vercel`控制台也能看到这个服务。 47 | 48 | 6. **绑定自己的域名**,如果使用默认分配的域名其实也是被墙的,所以必须绑定自己的域名. 49 | 50 | ![image-20230905150832916](assets/image-20230905150832916.png) 51 | 52 | 7. 在域名解析控制台添加对应的CNAME,记录值就是`cname.vercel-dns.com`,添加完成后解析成功就能正常访问了,ssl证书也省了。 53 | 54 | 最后验证一下吧! 打开绑定的域名 `xxxx.com` 可以看到谷歌翻译界面就表示成功了. 55 | 56 | 57 | ## 使用cloudflare workers进行反向代理 58 | > 1. 必须将域名的dns转移到cloudflare 59 | > 2. 免费的用户每日免费10万次请求 60 | 61 | 脚本: 62 | ``` 63 | const hostname = "https://translate.google.com" 64 | 65 | function handleRequest(request) { 66 | let url = new URL(request.url); 67 | return fetch(new Request(hostname + url.pathname,request)) 68 | } 69 | 70 | addEventListener("fetch", event => { 71 | event.respondWith(handleRequest(event.request)) 72 | }) 73 | ``` 74 | 75 | ## 使用Nginx进行配置反向代理 76 | 77 | ### 必要条件 78 | 79 | - 国外vps,可以直接访问google.com的 80 | 81 | - 注册一个自己的域名,并开了SSL访问,自己腾讯云申请一个免费一年的证书即可 82 | 83 | 下面以宝塔的Nginx为例: 84 | 85 | 新建一个站点,选择 `反向代理`: 86 | 87 | ![image-20230905151501383](assets/image-20230905151501383.png) 88 | 89 | 目标URL填写:`https://translate.google.com`, 直接点击保存即可! 90 | 91 | 如果无法使用可以复制下面我的配置项内容: 92 | 93 | ``` 94 | 95 | #PROXY-START/ 96 | 97 | location ^~ / 98 | { 99 | proxy_pass https://translate.google.com/; 100 | proxy_set_header Host translate.google.com; 101 | proxy_set_header X-Real-IP $remote_addr; 102 | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 103 | proxy_set_header REMOTE-HOST $remote_addr; 104 | proxy_set_header Upgrade $http_upgrade; 105 | proxy_set_header Connection $connection_upgrade; 106 | proxy_http_version 1.1; 107 | # proxy_hide_header Upgrade; 108 | proxy_ssl_server_name on; 109 | proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 110 | 111 | add_header X-Cache $upstream_cache_status; 112 | 113 | #Set Nginx Cache 114 | 115 | 116 | if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" ) 117 | { 118 | expires 1m; 119 | } 120 | proxy_ignore_headers Set-Cookie Cache-Control expires; 121 | proxy_cache cache_one; 122 | proxy_cache_key $host$uri$is_args$args; 123 | proxy_cache_valid 200 304 301 302 10m; 124 | } 125 | 126 | #PROXY-END/ 127 | ``` 128 | 129 | ![image-20230905151619657](assets/image-20230905151619657.png) 130 | 131 | 点击`配置文件`后直接使用我上面的配置即可! 132 | 133 | 最后访问你的域名验证下是否可以直接访问`谷歌翻译`页面吧! 134 | -------------------------------------------------------------------------------- /assets/image-20230905150832916.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RipperTs/proxy_tutorial_for_translation/f68b43747effb4d52d9dfb01ef1bb7741b03183f/assets/image-20230905150832916.png -------------------------------------------------------------------------------- /assets/image-20230905151501383.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RipperTs/proxy_tutorial_for_translation/f68b43747effb4d52d9dfb01ef1bb7741b03183f/assets/image-20230905151501383.png -------------------------------------------------------------------------------- /assets/image-20230905151619657.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/RipperTs/proxy_tutorial_for_translation/f68b43747effb4d52d9dfb01ef1bb7741b03183f/assets/image-20230905151619657.png --------------------------------------------------------------------------------