You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

远程开发VM上的Browsersync无法在本地浏览器正常工作

Troubleshooting Browsersync + HTTPS Proxy Issues with PuTTY Port Forwarding

Hey Tom, let's work through this problem step by step—this setup can get tricky with HTTPS, port forwarding, and proxy layers, but we can get your API requests working smoothly again.

1. First: Verify Your PuTTY Port Forwarding is Solid

Before diving into Browsersync, make sure the base port forwarding works correctly:

  • Double-check your PuTTY config: You need a Local port forward set to 7443 (local) → <remote-vm-ip>:7443 (remote). Avoid Remote/Dynamic modes here.
  • Test direct access first: Open your browser or run curl -v https://localhost:7443 to confirm you can reach the vert.x app without Browsersync. If this fails:
    • Ensure your remote VM's firewall allows inbound traffic on 7443.
    • Check that your vert.x app is bound to 0.0.0.0 (not just localhost on the VM)—otherwise, the app won't accept connections forwarded from PuTTY.

2. Fix Browsersync HTTPS + Proxy Configuration

The ECONNRESET/504 errors usually stem from misconfigured proxy handling of HTTPS, or certificate validation issues. Here's a corrected setup:

Example Working Configuration

const browserSync = require('browser-sync').create();
const { createProxyMiddleware } = require('http-proxy-middleware');

browserSync.init({
  // Use your self-signed SSL cert for Browsersync
  https: {
    key: './localhost.key',
    cert: './localhost.crt'
  },
  server: './your-static-files-dir', // Point to your local frontend files
  middleware: [
    createProxyMiddleware('/api', {
      target: 'https://localhost:7443', // Match your forwarded HTTPS port
      changeOrigin: true, // Critical for HTTPS proxying
      secure: false, // Disable certificate validation (safe for dev only—your forwarded port uses a self-signed cert)
      timeout: 60000, // Increase timeout to avoid 504s
      proxyTimeout: 60000,
      pathRewrite: { '^/api': '/api' } // Adjust if your vert.x API uses a different base path
    })
  ]
});

3. Debug ECONNRESET & 504 Errors

  • Check request routing: Open your browser's dev tools > Network tab. Confirm API requests are hitting https://localhost:<browsersync-port>/api/... (not the raw 7443 port).
  • Inspect vert.x logs: SSH into your remote VM and check the vert.x app logs. If you don't see incoming API requests, your proxy path matching is off—tweak the pathRewrite or proxy target path.
  • Disable local security tools: Temporary turn off your firewall/antivirus—sometimes they block proxy connections between Browsersync and the forwarded port.

4. Quick Sanity Check

Make sure you're accessing the Browsersync instance (default port 3000, e.g., https://localhost:3000) instead of directly hitting localhost:7443. Browsersync acts as the middle layer, so all traffic should go through its port.

内容的提问来源于stack exchange,提问作者Tom Trabue

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:27:31