Self-Hosting a GitHub Proxy Relay: Enterprise & Personal Deployment Guide
Table of Contents (5 sections)
1. Why and When to Self-Host a Dedicated Proxy Node
While public services like GitHub Acceleration Doctor (ghproxy.icu) provide an immediate, zero-configuration solution for public repositories and Release assets, specific organizational and technical requirements warrant deploying a dedicated private proxy node:
- Enterprise Private Code Isolation: Organizations with strict compliance policies require all network transit to stay within dedicated, audited private infrastructure;
- Internal CI/CD Pipeline Dedicated Bandwidth: Large engineering teams building hundreds of Docker images hourly benefit from dedicated gigabit transit links without shared public rate limits;
- Private Repository Credential Forwarding: Authenticated internal access using company-wide service tokens or private Git credentials.
2. Architecture Comparison: Cloudflare Workers vs. Dedicated BGP VPS
| Dimension | Cloudflare Workers (Serverless) | Standalone Dedicated VPS (Nginx) |
|---|---|---|
| Infrastructure Cost | Free tier available; pay-per-request | ~$5 - $20/month for dedicated VPS |
| Bandwidth Limits | 100,000 requests/day on free tier | Dedicated unmetered or multi-TB bandwidth |
| Large File (>100MB) Handling | Can hit Worker CPU/memory run limits | Unlimited stream forwarding with zero buffering |
| Deployment Complexity | Low (Web dashboard paste & save) | Medium (Linux, SSL certificates, Nginx tuning) |
| Best-Fit Scenario | Personal script pulls & light dev | Enterprise CI/CD, Monorepos, heavy binary downloads |
3. Option A: Cloudflare Workers Serverless Deployment
For personal use, Cloudflare Workers provides a rapid serverless reverse proxy:
// Cloudflare Worker Script: Streaming GitHub Relay
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
async function handleRequest(request) {
const url = new URL(request.url);
// Strip initial slash to extract target URL
let targetUrl = url.pathname.slice(1) + url.search;
if (!targetUrl.startsWith('http://') && !targetUrl.startsWith('https://')) {
targetUrl = 'https://' + targetUrl;
}
// Security check: only allow GitHub domains
const targetHost = new URL(targetUrl).hostname;
const allowedHosts = [
'github.com',
'raw.githubusercontent.com',
'assets-cdn.github.com',
'objects.githubusercontent.com',
'gist.github.com'
];
if (!allowedHosts.some(h => targetHost.endsWith(h))) {
return new Response('Target host not allowed', { status: 403 });
}
// Construct outbound request with stream passthrough
const modifiedHeaders = new Headers(request.headers);
modifiedHeaders.set('Host', targetHost);
modifiedHeaders.delete('cf-connecting-ip');
modifiedHeaders.delete('x-forwarded-for');
const response = await fetch(targetUrl, {
method: request.method,
headers: modifiedHeaders,
redirect: 'follow'
});
// Relay response with permissive CORS
const newResponseHeaders = new Headers(response.headers);
newResponseHeaders.set('Access-Control-Allow-Origin', '*');
newResponseHeaders.set('Access-Control-Allow-Methods', 'GET, HEAD, POST, OPTIONS');
return new Response(response.body, {
status: response.status,
statusText: response.statusText,
headers: newResponseHeaders
});
}
4. Option B: Standalone Nginx Production Configuration
For enterprise clusters and large binary assets, deploy on an Asia-Pacific or European VPS running Nginx:
server {
listen 80;
listen 443 ssl http2;
server_name proxy.example.com;
# SSL Certificates
ssl_certificate /etc/letsencrypt/live/proxy.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/proxy.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
# High-performance DNS resolution
resolver 8.8.8.8 1.1.1.1 valid=300s ipv6=off;
resolver_timeout 5s;
# Root proxy rule
location ~* ^/(https?://.+)$ {
set $target_url $1;
# Disable disk buffering for instant streaming
proxy_buffering off;
proxy_request_buffering off;
proxy_http_version 1.1;
# Pass through byte-range requests for Aria2 / IDM
proxy_set_header Range $http_range;
proxy_set_header If-Range $http_if_range;
# Forward request to upstream
proxy_pass $target_url;
proxy_redirect default;
# Timeouts for large multi-gigabyte transfers
proxy_connect_timeout 30s;
proxy_read_timeout 600s;
proxy_send_timeout 600s;
}
}
5. Security Hardening & Rate Limiting
When running a private or enterprise proxy, implement defensive rate-limiting and domain filtering to prevent public scanning or traffic abuse:
# Define rate limiting zone
limit_req_zone $binary_remote_addr zone=git_proxy:10m rate=30r/s;
# In your location block:
limit_req zone=git_proxy burst=50 nodelay;
# Restrict allowed upstream domains using regex
if ($target_url !~* ^https?://([^/]+\.)?(github\.com|githubusercontent\.com)/) {
return 403 "Forbidden: Only GitHub domains are allowed.";
}
By enforcing domain boundaries, streaming directly through kernel memory, and pairing with high-speed transit links, your team achieves an enterprise-grade, high-availability Git acceleration infrastructure.