├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── README_zh.md ├── examples ├── github ├── google ├── google-scholar ├── nytimes ├── pornhub │ ├── ci.phncdn.com │ └── www.pornhub.com ├── wikipedia └── wikipedia-zh ├── package-lock.json ├── package.json └── src └── index.js /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: Siujoeng-Lau 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the bug. 15 | 16 | **Screenshots** 17 | If applicable, add screenshots to help explain your problem. 18 | 19 | **Additional context** 20 | Add any other context about the problem here. 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: Siujoeng-Lau 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | **/*.rs.bk 3 | Cargo.lock 4 | bin/ 5 | pkg/ 6 | wasm-pack.log 7 | worker/ 8 | node_modules/ 9 | .cargo-ok 10 | wrangler.toml 11 | dist/ 12 | .DS_store -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at admin@siujoeng-lau.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Siujoeng-Lau 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |  2 | 3 |
4 | 5 | # Workers-Proxy 6 | 7 | [](https://github.com/Berkeley-Reject/Workers-Proxy/blob/master/LICENSE) 8 | [](https://github.com/Berkeley-Reject/Workers-Proxy/issues) 9 | [](https://github.com/Berkeley-Reject/Workers-Proxy/stargazers) 10 | 11 | [Issues](https://github.com/Berkeley-Reject/Workers-Proxy/issues) | 12 | [Pull requests](https://github.com/Berkeley-Reject/Workers-Proxy/pulls) | 13 | [Contributors](https://github.com/Berkeley-Reject/Workers-Proxy/graphs/contributors) 14 | 15 |
16 | 17 | ## Introduction 18 | 19 | Workers-Proxy is a lightweight Javascript [Reverse Proxy](https://www.cloudflare.com/learning/cdn/glossary/reverse-proxy/) based on [Cloudflare Workers](https://workers.cloudflare.com/). 20 | 21 | Users could deploy the reverse proxy on Cloudflare's global network without setting up virtual private servers and configuring Nginx or Apache. 22 | 23 | ### Features 24 | 25 | * Build mirror websites 26 | * Improve loading speed with Cloudflare's global network 27 | * Increase security (Hide IP addresses of websites) 28 | * Block specific areas or IP addresses 29 | * Redirect mobile users to different web pages 30 | 31 | ## Demo 32 | 33 | [GitHub](https://cdn.reverse-proxy.live) (This demo may not be available in specific regions.) 34 | 35 | [University of California, Los Angeles (UCLA)](https://ucla.reverse-proxy.live) 36 | 37 | [Python Documentation](https://python.reverse-proxy.live) 38 | 39 | 40 | ## Getting Started 41 | 42 | ### Build and Deploy 43 | 44 | #### Deploy with Wrangler 45 | 46 | 1. [Install Wrangler.](https://github.com/cloudflare/wrangler#installation) 47 | 48 | 2. Generate a new project. 49 | 50 | ``` 51 | wrangler generate my-workers-proxy https://github.com/Berkeley-Reject/Workers-Proxy 52 | ``` 53 | 54 | 3. [Configure](https://developers.cloudflare.com/workers/quickstart/#configure) your project's `wrangler.toml` file to prepare your project for deployment. 55 | 56 | ``` 57 | wrangler config 58 | ``` 59 | 60 | 4. Build and deploy on Cloudflare Workers. 61 | 62 | ``` 63 | wrangler build 64 | wrangler publish 65 | ``` 66 | 67 | #### Deploy manually 68 | 69 | 1. Navigate to [Cloudflare Workers](https://workers.cloudflare.com), register or sign in your Cloudflare account, and set custom subdomain for workers, and create a new Worker. 70 | 71 | 2. Customize '[src/index.js](https://github.com/Berkeley-Reject/Workers-Proxy/blob/master/src/index.js)', paste the code into Cloudflare online editor to replace the default one. 72 | 73 | 3. Change name of your Worker, save and deploy it, and check whether its performance fulfills your demand. 74 | 75 | ### Bind to Custom Domain 76 | 77 | 1. Check whether your domain is currently under Cloudflare's protection. 78 | 79 | 2. Navigate to the dashboard of your domain, select 'Workers' page, and click on 'Add Route'. 80 | 81 | 3. Type `https://4 | 5 | # Workers-Proxy 6 | 7 | [](https://github.com/Berkeley-Reject/Workers-Proxy/blob/master/LICENSE) 8 | [](https://github.com/Berkeley-Reject/Workers-Proxy/issues) 9 | [](https://github.com/Berkeley-Reject/Workers-Proxy/stargazers) 10 | 11 | [Issues](https://github.com/Berkeley-Reject/Workers-Proxy/issues) | 12 | [Pull requests](https://github.com/Berkeley-Reject/Workers-Proxy/pulls) | 13 | [贡献者](https://github.com/Berkeley-Reject/Workers-Proxy/graphs/contributors) 14 | 15 |
16 | 17 | ## 介绍 18 | 19 | Workers-Proxy 是基于 [Cloudflare Workers](https://workers.cloudflare.com/) 的轻量级 Javascript [反向代理](https://www.cloudflare.com/learning/cdn/glossary/reverse-proxy/). 20 | 21 | 用户无需购买主机并配置 Web 服务器 (例如 Nginx 或 Apache) 即可在 Cloudflare 的全球网络上部署反向代理. 22 | 23 | ### 功能 24 | 25 | * 搭建网站镜像 26 | * 通过 Cloudflare 的全球网络加速前端资源访问 27 | * 增加安全性, 隐藏网站的真实 IP 地址 28 | * 屏蔽特定地区或 IP 地址 29 | * 将移动设备用户转发到不同网站 30 | 31 | ## 示例 32 | 33 | [GitHub](https://cdn.reverse-proxy.live) (该示例在部分地区无法使用) 34 | 35 | [University of California, Los Angeles (UCLA)](https://ucla.reverse-proxy.live) 36 | 37 | [Python 文档](https://python.reverse-proxy.live) 38 | 39 | ## 配置教程 40 | 41 | ### 安装和部署 42 | 43 | #### 使用 Wrangler 部署 44 | 45 | 1. [安装 Wrangler.](https://github.com/cloudflare/wrangler#installation) 46 | 47 | 2. 创建一个新的项目. 48 | 49 | ``` 50 | wrangler generate my-workers-proxy https://github.com/Berkeley-Reject/Workers-Proxy 51 | ``` 52 | 53 | 3. [配置](https://developers.cloudflare.com/workers/quickstart/#configure)该项目的 `wrangler.toml` 文件来准备部署你的项目. 54 | 55 | ``` 56 | wrangler config 57 | ``` 58 | 59 | 4. 构建并部署于 Cloudflare Workers. 60 | 61 | ``` 62 | wrangler build 63 | wrangler publish 64 | ``` 65 | 66 | #### 手动部署 67 | 68 | 1. 转到 [Cloudflare Workers](https://workers.cloudflare.com), 注册或登录 Cloudflare 账号, 为 Workers 设置子域名, 创建新的 Worker. 69 | 70 | 2. 自定义 '[src/index.js](https://github.com/Berkeley-Reject/Workers-Proxy/blob/master/src/index.js)', 将代码复制到在线编辑器中, 替换默认代码. 71 | 72 | 3. 更改 Worker 名称, 保存代码并部署, 测试反向代理是否符合需求. 73 | 74 | ### 绑定自定义域名 75 | 76 | 1. 检查域名是否接入 Cloudflare. 77 | 78 | 2. 跳转到域名的控制面板, 选择 'Workers' 页面, 点击 'Add Route'. 79 | 80 | 3. 在 `Route` 中输入 `https://<自定义域名>/*` 并且选择刚创建的 Worker. 81 | 82 | 4. 为自定义域名添加 CNAME DNS 记录. 在 DNS 页面中, 在 'Name' 区域输入自定义域名的子域名 (或者 @), 在 'Target' 区域输入 Worker 的**二级域名** (例如 test.workers.dev), 将代理状态选择为 '代理'. 83 | 84 | ### 自定义 index.js 85 | 86 | 在 'index.js' 文件顶部有一些常量. 87 | 88 | 为了自定义 Workers-Proxy 反向代理, 请根据需求编辑这些常量. 89 | 90 | ``` 91 | // 代理网站 92 | const upstream = 'www.google.com' 93 | 94 | // 代理网站的目录 95 | const upstream_path = '/' 96 | 97 | // 手机用户代理网站 98 | const upstream_mobile = 'www.google.com' 99 | 100 | // 屏蔽国家和地区 101 | const blocked_region = ['CN', 'KP', 'SY', 'PK', 'CU'] 102 | 103 | // 屏蔽 IP 地址 104 | const blocked_ip_address = ['0.0.0.0', '127.0.0.1'] 105 | 106 | // 源站是否开启 HTTPS 107 | const https = true 108 | 109 | // 是否允许浏览器缓存 110 | const disable_cache = false 111 | 112 | // 文本替换 113 | const replace_dict = { 114 | '$upstream': '$custom_domain', 115 | '//google.com': '' 116 | } 117 | ``` 118 | 119 | ### 配置模板 120 | 121 | * [Google](https://github.com/Berkeley-Reject/Workers-Proxy/blob/master/examples/google) 122 | * [Google Scholars](https://github.com/Berkeley-Reject/Workers-Proxy/blob/master/examples/google-scholar) 123 | * [GitHub](https://github.com/Berkeley-Reject/Workers-Proxy/blob/master/examples/github) 124 | * [Wikipedia](https://github.com/Berkeley-Reject/Workers-Proxy/blob/master/examples/wikipedia) 125 | * [Wikipedia (Chinese)](https://github.com/Berkeley-Reject/Workers-Proxy/blob/master/examples/wikipedia-zh) 126 | * [The New York Times](https://github.com/Berkeley-Reject/Workers-Proxy/blob/master/examples/nytimes) 127 | * [Pornhub](https://github.com/Berkeley-Reject/Workers-Proxy/blob/master/examples/pornhub) 128 | 129 | ### 部署多个域名 130 | 131 | 如果被反代的网站使用其他域名的静态资源时, 可以部署多个 Workers-Proxy 并配置文本替换. 132 | 133 | 1. www.google.com 使用位于 www.gstatic.com 的静态资源 134 | 2. 部署 Workers-Proxy A, 用于代理 www.gstatic.com 135 | 3. 部署 Workers-Proxy B, 用于代理 www.google.com 136 | 4. 配置 Workers-Proxy B 的文本替换: 137 | ``` 138 | const replace_dict = { 139 | '$upstream': '$custom_domain', 140 | 'www.gstatic.com': '