A collection of lightweight, serverless Reverse Proxy scripts for Cloudflare Workers — no servers, no VMs, no Nginx required.
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.
| 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 |
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)
Go to dash.cloudflare.com → Workers & Pages → Create Application → Create Worker.
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.
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': '',
},
};- 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:
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.
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.
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.
Extends the proxy with performance optimizations: static asset caching, image compression (Polish/Mirage), JavaScript minification, scrape shielding, and region-based routing.
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.
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.
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.
| 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 |
- 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.
| 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 |
This project is licensed under the MIT License. See the LICENSE file for details.
© 2026 OshekharO · CF-REVERSE-PROXY