I’m trying to setup external access to my Valheim server and it doesn’t seem to work via proxy, I wonder if anyone has any comments or similar experience.
What I have is:
- VPS with external IP, running one instance of Nginx as a proxy [1], and a WireGuard host.
- Home server, running another Nginx as proxy [2], and a WireGuard peer.
- A bunch of docker containers with stuff.
This setup has been working great for a long time for HTTP(S) traffic, where the flow is:
A device connects → Nginx[1] accepts connections and forwards them into WireGuard tunnel → Nginx[2] accepts connections from the tunnel and forwards them to corresponding containers → services in containers do their thing.
Now I would like to add Valheim to the mix. I used lloesche/valheim-server, configured it, and exposed 2456 and 2457 ports (as 9100 and 9101 in the example below). It works fine if I connect to it directly (within LAN) - I can join the server, load into the world, etc. But I get “Failed to connect” message if I try to connect via external address.
In other words, this works:
(( LAN (Valheim) <=> (MyPC) ))
But this doesn’t:
(( LAN (Valheim) (MyPC) )) ((VPS))
^ ^=========^ ^
^======================^
Which indicates a problem at proxy or VPN level, or some side-effect of Valheim network handling in this case.
Nginx[1] config is roughly this:
stream {
server {
listen PUBLIC_IP:42456 udp reuseport;
proxy_pass WG_IP:12456;
}
server {
listen PUBLIC_IP:42457 udp reuseport;
proxy_pass WG_IP:12457;
}
}
And Nginx[2] is:
stream {
server {
listen WG_IP:12456 udp reuseport;
proxy_pass LAN_IP:9100;
proxy_requests 999999;
}
server {
listen WG_IP:12457 udp reuseport;
proxy_pass LAN_IP:9101;
proxy_requests 999999;
}
}
VPS ports are opened via ufw: “42456/udp ALLOW IN Anywhere” etc.
I did manage to make netcat work, i.e. I run
$ nc -uvl LAN_IP 9100
on home server and
$ nc -uv PUBLIC_IP 42456
on my pc and it works mostly as expected (the output seems to be truncated to MTU size but I doubt that’s an issue).
So the whole reverse-vpn-proxy idea works in principle, just not in Valheim. Neither Valheim’s Player.log nor Nginx logs seem to have anything odd.
What I tried so far:
- setting WireGuard’s MTU to 1200
- omitting “proxy_requests”
- omitting “reuseport”
- using “proxy_protocol on;”
- using “proxy_responses 0;”
What I will not use:
- iptables
- another VPN
- port forwarding