跪拜 Guibai
← All articles
Artificial Intelligence

A Local TLS Proxy That Reroutes LM Studio Downloads Through China's Hugging Face Mirror

By 回归272 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

LM Studio's downloader bypasses the system proxy and ignores standard hosts-only hacks, so developers outside China who use it with a VPN get throttled to ~100 KB/s from Cloudflare. This proxy-and-hosts combination gives full-speed downloads over a domestic Chinese broadband link without consuming proxy data, and the same TLS interception pattern applies to any Electron app that bundles its own Node HTTP stack.

Summary

LM Studio's Electron-based Node downloader ignores the Windows system proxy and, when its built-in HF proxy is enabled, first hops to search.lmstudio.ai — not huggingface.co. A Python TLS termination proxy listening on localhost:443 intercepts those requests, strips the /v1/hf-proxy prefix, rewrites the Host header to hf-mirror.com, and connects directly to the mirror's IP over a domestic broadband link. The mirror's 302 redirect to us.aws.cdn.hf.co is handled by a separate hosts entry pointing to a directly reachable CloudFront edge IP, keeping large file transfers out of the local proxy.

The setup requires generating a local CA and a server certificate whose SAN includes search.lmstudio.ai, huggingface.co, hf.co, cdn-lfs.huggingface.co, and us.aws.cdn.hf.co. That CA must be installed both in the Windows root store and exposed to Node via the NODE_EXTRA_CA_CERTS environment variable. IPv6 hosts entries are mandatory because LM Studio will otherwise prefer Cloudflare's IPv6 addresses. Clash and TUN must be fully exited during downloads, and any leftover HTTP_PROXY variables pointing to dead proxy ports will cause Node to time out.

A PowerShell launcher script optionally adds Chromium host-resolver rules as a second layer of DNS enforcement, and a VBS script placed in the Windows Startup folder runs the proxy silently on login. The result is multi-MB/s download speeds without routing model weights through a VPN or hitting Hugging Face's overseas rate limiting.

Takeaways
LM Studio's Node/undici downloader does not read the Windows system proxy, so Clash or VPN settings have no effect on model downloads.
Enabling useHFProxy rewrites the first hop to search.lmstudio.ai, not hf-mirror.com; a hosts entry for huggingface.co alone is insufficient.
A local TLS proxy on 127.0.0.1:443 strips the /v1/hf-proxy path prefix and rewrites the Host header to hf-mirror.com before connecting to the mirror's IP directly.
The server certificate's SAN must include search.lmstudio.ai, huggingface.co, hf.co, cdn-lfs.huggingface.co, and us.aws.cdn.hf.co, or Node will reject the handshake.
Node requires the NODE_EXTRA_CA_CERTS environment variable pointing to the local CA certificate; installing the CA into the Windows root store alone is not enough.
IPv6 hosts entries (::1) are mandatory because LM Studio will prefer Cloudflare's IPv6 addresses if only IPv4 is hijacked.
us.aws.cdn.hf.co must point to a directly reachable CloudFront edge IP, not 127.0.0.1, to avoid certificate mismatches and unnecessary proxy load for large files.
Leftover HTTP_PROXY or HTTPS_PROXY variables pointing to a dead Clash port cause Node to hang on a refused connection; they must be deleted from the user environment.
hf-mirror.com rejects non-Chinese IPs, so the entire setup only works when the local broadband egress is a domestic Chinese IP.
Download speeds jump from ~100 KB/s to several MB/s once the proxy, hosts, and certificate chain are all correctly configured.
Conclusions

The core friction is architectural: Electron apps ship their own Node runtime, which ignores OS-level proxy and DNS settings that developers assume are universal. This proxy pattern is a reusable fix for any Electron tool that downloads from Hugging Face.

LM Studio's useHFProxy feature is a well-intentioned relay that actually complicates local mirroring because it introduces an extra hostname (search.lmstudio.ai) that must be separately hijacked and included in the TLS certificate.

The checklist of 13 items and 10 common pitfalls reflects how brittle the setup is — a single missing IPv6 hosts line or a stale HTTP_PROXY variable silently breaks the entire chain, and the failure mode is just slow downloads with no clear error.

Hardcoding mirror and CDN IPs creates a maintenance burden: those addresses change over time, and the tutorial explicitly warns readers to re-test them on the day of replication rather than blindly copying the values.

Concepts & terms
TLS termination proxy
A proxy that decrypts incoming HTTPS traffic using its own certificate, inspects or modifies the HTTP request, then re-encrypts it when forwarding to the upstream server. Here it rewrites the Host header and URL path before sending the request to hf-mirror.com.
SAN (Subject Alternative Name)
An extension in X.509 certificates that lists the hostnames the certificate is valid for. If a client connects to a hostname not in the SAN, TLS handshake fails. This setup requires search.lmstudio.ai and several Hugging Face domains in the SAN.
NODE_EXTRA_CA_CERTS
A Node.js environment variable that specifies additional CA certificates to trust beyond the system root store. Required here because LM Studio's bundled Node runtime does not read the Windows certificate store by default.
CloudFront edge IP
An IP address of an AWS CloudFront point-of-presence server. Hugging Face stores large model files on CloudFront; the tutorial resolves us.aws.cdn.hf.co to a specific edge IP that is directly reachable from the user's network.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗