[FRP + Vite Pitfalls] localhost works but the public address returns 502? Debugging IPv6, service reloads and duplicate proxy names
Translated from Chinese by AI (claude-opus-5-5). It may differ from the original.
A pitfall diary, summarized by AI ---- the pitfalls you fall into are the ones you truly remember
Pitfall 1: localhost works, but 127.0.0.1 can't connect (causing a public 502)
1. Symptoms and investigation
The local Vite service runs on port 3200. Opening http://localhost:3200 in the browser works, but running curl.exe http://127.0.0.1:3200 fails with Failed to connect: Could not connect to server.
Check which addresses the port is listening on:
powershellnetstat -ano | findstr :3200
# 输出:TCP [::1]:3200 LISTENING
2. Root cause
- localhost: modern systems and Node.js 17+ resolve it to the IPv6 address [::1] first.
- 127.0.0.1: the IPv4 loopback address. By default Vite only binds to the IPv6 [::1], so nothing is listening on IPv4 at all.
- Knock-on effect: frpc.toml sets localIP = "127.0.0.1", so when FRP forwards public requests to the local 127.0.0.1:3200 they are refused, which shows up to the outside world as HTTP 502.
Address | Protocol | Listening | Result |
|---|---|---|---|
http://localhost:3200 | IPv6 preferred (::1) | Listening | ✅ OK |
http://[::1]:3200 | IPv6 loopback only | Listening | ✅ OK |
http://127.0.0.1:3200 | IPv4 loopback only | Not listening | ❌ Connection refused |
3. Fix
Edit vite.config.ts and set host: '0.0.0.0' explicitly (listen on all interfaces, dual stack):
tsexport default defineConfig({
server: {
host: '0.0.0.0',
port: 3200,
},
})
Pitfall 2: edited frps.toml, but the port change didn't take effect
1. Symptoms and root cause
After changing bindPort = 7100 on the server I ran systemctl start frps, but the client still reported session shutdown.
- Cause: systemctl start only starts services that aren't already running. frps had been running in the background for months, so start doesn't reload the configuration.
2. Fix
bashsudo systemctl restart frps # 重启以加载新配置
ss -lntp | grep 7100 # 确认 7100 端口已处于 LISTEN 状态
Pitfall 3: duplicate names in [[proxies]] proxy entries
1. Symptoms and root cause
frpc.toml defines several proxy sections, but their name fields use the same value:
toml# ❌ 错误:两处代理 name 重复
[[proxies]]
name = "mqtt_remote"
localPort = 1883
remotePort = 6183
[[proxies]]
name = "mqtt_remote"
localPort = 3200
remotePort = 6001
The client log reports: start error: proxy [mqtt_remote] already exists. In FRP, name is the unique ID of each proxy.
2. Fix
Make sure every proxy entry's name is globally unique:
toml# ✅ 正确配置
[[proxies]]
name = "mqtt_remote"
type = "tcp"
localIP = "127.0.0.1"
localPort = 1883
remotePort = 6183
[[proxies]]
name = "web_3200"
type = "tcp"
localIP = "127.0.0.1"
localPort = 3200
remotePort = 6001
🛠️ Standard troubleshooting checklist
text公网请求 (38.95.74.213:6001) ──> frps 服务端 ──> frpc 客户端 ──> 本地服务 (127.0.0.1:3200)
When tunneling breaks, check the four links in order: "server -> local service -> network connectivity -> logs":
- Check the server is listening: ss -lntp | grep frps (confirm the 7100 control port and the mapped ports are in the LISTEN state).
- Test that the local service is reachable:
(if even local IPv4 doesn't connect, FRP is bound to return 502; change Vite to 0.0.0.0 first)powershellTest-NetConnection 127.0.0.1 -Port 3200
Test-NetConnection 127.0.0.1 -Port 1883 - Test the public port:
powershellTest-NetConnection 38.95.74.213 -Port 6001 - Check the client/server logs: look in frpc.log or frps.log for proxy already exists or authentication errors.
📌 Key takeaways
- localhost ≠ 127.0.0.1: when a connection fails, first run netstat -ano | findstr :端口 to see whether it's [::1] or 127.0.0.1 / 0.0.0.0.
- Always restart after changing the config: systemctl start won't reload a process that's already running.
- [[proxies]] names must be unique: name is FRP's unique proxy ID.
Comments
No comments yet. Say something?