CF-REVERSE-PROXY
A collection of lightweight, serverless Reverse Proxy scripts for Cloudflare Workers β no servers, no VMs, no Nginx required.
π Overview
CF-REVERSE-PROXY lets you deploy a fully functional reverse proxy on Cloudflare's global edge network in minutes. Map any custom domain to any upstream target, enforce access controls, rewrite content on the fly, and serve your users with minimal latency β all without managing infrastructure.
β¨ Features
| Feature | Description |
|---|---|
| π Domain & Subdomain Mapping | Map one or more custom domains/subdomains to upstream targets |
| π Region & IP Blocking | Deny access from specific countries (ISO 3166-1 alpha-2) or IP addresses |
| π URL Rewriting | Automatically rewrite URLs in HTML, JS, CSS, and JSON responses |
| π§ Text Replacement Engine | Replace arbitrary strings in response bodies via a simple config dictionary |
| β‘ HTMLRewriter Support | Stream-based, efficient HTML transformation using Cloudflare's native HTMLRewriter API |
| π‘οΈ Security Headers | Inject X-Content-Type-Options, X-Frame-Options, X-XSS-Protection, and more |
| π« Ad Removal | Strip ad-injecting <script> and <iframe> blocks from proxied pages |
| π CORS Support | Adds appropriate CORS headers so proxied resources load cleanly in browsers |
| βοΈ Zero Infrastructure | 100% serverless β runs on Cloudflare's edge, no VMs or containers needed |
| π HTTPS Enforcement | Force all upstream connections to use HTTPS |
| β»οΈ Cache Control | Enable or disable caching with a single config flag |
π Repository Structure
CF-REVERSE-PROXY/
βββ Script/
βββ xiaoyang-sde/ # Original lightweight reverse proxy
βββ viperadnan/ # Booster β speed, caching, firewall, and route optimizations
βββ KusakabeSi/ # Multi-site proxy with string replacement & ad removal
βββ Clansty/ # Telegram channel preview reverse proxy
βββ Mikotwa/ # HTMLRewriter-based proxy
βββ ymyuuu/ # Simple general-purpose reverse proxy
βββ OshekharO/ # Enhanced proxy with full subdomain mapping (recommended)
π Quick Start
1. Open Cloudflare Workers
Go to dash.cloudflare.com β Workers & Pages β Create Application β Create Worker.
2. Paste the Script
Pick the script that fits your use case (see Script Variants), copy its contents, and paste it into the Cloudflare Workers online editor, replacing the default code.
3. Configure the Script
Edit the config object (or top-level constants) at the top of the script:
const config = {
// Map incoming host β upstream target
domain_map: {
'proxy.yourdomain.com': 'www.example.com',
'cdn.yourdomain.com': 'cdn.example.com',
},
default_target: 'www.example.com',
// Block access by country code (ISO 3166-1 alpha-2)
blocked_region: ['CN', 'KP', 'SY', 'PK', 'CU'],
// Block specific IP addresses
blocked_ip_address: ['0.0.0.0', '127.0.0.1'],
// Force HTTPS for upstream requests
https: true,
// Disable response caching
disable_cache: true,
// Replace text in response bodies
replace_dict: {
'example.com': 'yourdomain.com',
'Premium': '',
},
};
4. Deploy & Bind a Custom Domain
- Click Save and Deploy in the Workers editor.
- In the Cloudflare dashboard, navigate to your domain β Workers β Add Route.
- Enter
https://proxy.yourdomain.com/*as the route and select your Worker. - Add a
CNAMEDNS record:- Name:
proxy(or@for root) - Target:
<your-worker-subdomain>.workers.dev - Proxy status: Proxied (orange cloud βοΈ)
- Name:
π¦ Script Variants
OshekharO/worker.js β Recommended
A full-featured reverse proxy with explicit subdomain mapping, security headers, CORS handling, redirect rewriting, and X-Pjax-Url support. Best for production use.
OshekharO/beta.js
An optimized variant of worker.js that adds streaming HTML transformation via the native HTMLRewriter API, a loop-detection guard, and configurable request timeout handling.
xiaoyang-sde/index.js
The original lightweight reverse proxy. Simple configuration with upstream, blocked_region, blocked_ip_address, and replace_dict constants. Great starting point for basic use cases.
viperadnan/booster.js
Extends the proxy with performance optimizations: static asset caching, image compression (Polish/Mirage), JavaScript minification, scrape shielding, and region-based routing.
KusakabeSi/worker.js
Supports multiple upstream sites within a single Worker. Includes string replacement, custom resource substitution, Cloudflare email-obfuscation bypass, and optional ad removal from <script> and <iframe> elements.
Clansty/proxy.js
Specifically designed to reverse-proxy Telegram channel preview pages, stripping the headers that prevent embedding so the channel can be shown in an <iframe> on your own website.
ymyuuu/worker.js
A straightforward general-purpose reverse proxy with CORS headers, relative-to-absolute path rewriting, redirect handling, and a user-friendly input UI when no target URL is provided.
βοΈ Configuration Reference
| Key | Type | Description |
|---|---|---|
domain_map |
Object |
Maps incoming hostnames to upstream target hostnames |
default_target |
string |
Fallback upstream when no mapping is found |
blocked_region |
string[] |
ISO 3166-1 alpha-2 country codes to block |
blocked_ip_address |
string[] |
IP addresses to block |
https |
boolean |
Use https: for upstream connections |
disable_cache |
boolean |
Set Cache-Control: no-store on responses |
replace_dict |
Object |
Key-value pairs for text replacement in response bodies |
security_headers |
Object |
Additional response headers to inject |
β οΈ Disclaimer
- This project is intended for educational and legitimate use only.
- Do not use this to proxy sites you do not own or have permission to mirror.
- Do not use this to violate Cloudflare's Terms of Service or any applicable laws.
- This script is free β do not sell it.
- The authors are not responsible for any misuse or legal consequences.
π€ Credits
| Contributor | Contribution |
|---|---|
| xiaoyang-sde | Original Workers-Proxy script |
| viperadnan-git | Booster β caching, optimization, firewall |
| KusakabeSi | Multi-site support, string replacement, ad removal |
| Mikotwa | HTMLRewriter integration |
| Clansty | Telegram channel proxy |
| ymyuuu | General-purpose proxy with UI |
| OshekharO | Repository maintainer & enhancements |
π License
This project is licensed under the MIT License. See the LICENSE file for details.
Β© 2026 OshekharO Β· CF-REVERSE-PROXY