代理伺服器可用於存取內部資源、繞過地域限制、隱藏真實 IP、內容過濾、流量審計。Windows 提供多層級設定入口,本文涵蓋 IE/Edge/Chrome 瀏覽器級、系統級 (WinHTTP/WinINET)、命令列、註冊表、群組原則、PAC 腳本等全方位配置指南。
inetcpl.cpl)。192.168.1.100:8080 或 proxy.company.com:3128)。192.168.*;*.local;<local>)。https://proxy.company.com/proxy.pac)。Win+I →「網路和 Internet」→「Proxy 伺服器」。⚠️ Win10 1709+ 此處設定會同步寫入 WinINET 註冊表,雙向同步。
# 設定 WinHTTP Proxy (影響 Windows Update、WinRM、PowerShell Remoting、.NET HttpClient 等) netsh winhttp set proxy proxy-server="192.168.1.100:8080" bypass-list="192.168.*;*.local;" # 查看當前 WinHTTP Proxy netsh winhttp show proxy # 重置 WinHTTP Proxy (直連) netsh winhttp reset proxy # 設定 WinINET Proxy (同 Internet 選項,需用戶上下文) # 註:netsh 不直接支援 WinINET 設定,需用 PowerShell 操作註冊表或呼叫 InternetSetOption API
# WinINET (當前用戶) Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -Name ProxyEnable -Value 1 Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -Name ProxyServer -Value '192.168.1.100:8080' Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -Name ProxyOverride -Value '192.168.*;*.local;' # WinHTTP (系統級,需管理員) $proxy = '192.168.1.100:8080' $bypass = '192.168.*;*.local; ' netsh winhttp set proxy proxy-server=$proxy bypass-list=$bypass
gpmc.msc → 建立/編輯 GPO →「使用者設定」→「原則」→「Windows 設定」→「Internet Explorer 維護」→「連線」→「Proxy 設定」。gpupdate /force 生效。function FindProxyForURL(url, host) {
// 內網直連
if (isPlainHostName(host) || shExpMatch(host, "*.local") || shExpMatch(host, "192.168.*") || shExpMatch(host, "10.*") || shExpMatch(host, "172.16.*"))
return "DIRECT";
// 特定域名走代理
if (shExpMatch(host, "*.google.com") || shExpMatch(host, "*.github.com") || shExpMatch(host, "*.stackoverflow.com"))
return "PROXY proxy.company.com:8080; PROXY backup.proxy.com:8080; DIRECT";
// 預設直連
return "DIRECT";
}
存為 proxy.pac 放入 Web 伺服器 (MIME: application/x-ns-proxy-autoconfig),客戶端填 https://pac.company.com/proxy.pac。
https://ip.sb / https://api.ipify.org / https://httpbin.org/ip 確認出口 IP 是否為代理 IP。curl -x https://192.168.1.100:8080 https://httpbin.org/ip 測試指定代理。netsh winhttp show proxy、reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings /v ProxyServer。/var/log/squid/access.log、Nginx: access.log) 確認請求到達。| 現象 | 原因 | 解決 |
|---|---|---|
| 瀏覽器能上網,Windows Update/Store 失敗 | 僅設 WinINET,未設 WinHTTP | 同步設定 WinHTTP (netsh winhttp set proxy) |
| 設定後立即失效 | GPO/MDM/第三方安全軟體強制覆蓋 | 檢查 RSOP、Intune/MDM 策略、安全軟體網路保護模組 |
| PAC 腳本不生效 | MIME 錯誤、編碼非 UTF-8、語法錯誤、HTTPS PAC 需信任憑證 | 瀏覽器直接開 PAC URL 驗證下載、簡化腳本排錯 |
| SOCKS5 代理無效 | WinINET/WinHTTP 不原生支援 SOCKS | 用 Proxifier/ProxyCap/Clash Verge/NFP 進行全域 SOCKS 轉發 |