How to nginx reverse proxy to a game server reddit / selfhosted ---------------------------------------------------------------------- sefFano · 2023-10-11 15:15 Ive recently been wondering if it is possible to reverse proxy a domain to my home server. I'm not exactly sure how reverse proxying tcp works in nginx. And wondered if it is possible at all? I have a vps with nginx, and want to proxy server.mydomain.com to my home ip address. So if I want to host any game my friends would just enter the address and connect to it. How would that work? And if doesn't work, what alternatives do I have? My IP is dynamic and I don't want a static one. So DNS won't really work for me ---------------------------------------------------------------------- VsevolodLNM · 2023-10-11 15:36 that wouldn't work, nginx reverse proxy would need a static ip... so your options are a vpn and tailscale if it works with tcp ---------------------------------------------------------------------- TBT_TBT · 2023-10-11 15:51 Use Tailscale on the server and share access to that particular machine with your friends. That way everything is safe (not accessible from outside the home) and you can invite only the people you want and also remove access based on users. ---------------------------------------------------------------------- lvlint67 · 2023-10-11 16:00 > So if I want to host any game my friends would just enter the address and connect to it. You create a dns A record at the domain to point to your ip. If the domain is already pointed at something use a subdomain. If that won't work, use a firewall proxy or something like haproxy. Some games like minecraft support srv dns records that can help ---------------------------------------------------------------------- DudeWithaTwist · 2023-10-11 16:14 You might be able to reverse proxy, but the issue is Nginx is a web server and video games don't use the HTTP protocol. You would be better off using an SRV record in the DNS side. At worst, just use the standard A and CNAME record and tell your friends to type in yourdomain:port to connect. ---------------------------------------------------------------------- Derf0293 · 2023-10-11 16:26 > nginx reverse proxy would need a static ip Technically it's possible using the stream module, ymmv though this isn't a default feature for nginx so OP will have to jump through some hoops to make it work. Not sure if tailscale would be less of a headache. ---------------------------------------------------------------------- Derf0293 · 2023-10-11 16:29 > the issue is Nginx is a web server and video games don't use the HTTP protocol Technically speaking it's possible using the stream module. OP will have to do some hoop jumping to make this work right, not sure if tailscale is any less of a headache to get working. http://nginx.org/en/docs/stream/ngx_stream_proxy_module.html ---------------------------------------------------------------------- DudeWithaTwist · 2023-10-11 16:38 Interesting, yea I have a feeling games might handle this differently. And like another comment mentioned, not all games might support SRV records. So tailscale, SRV, and the stream module may all produce different results. Depends how the game has implmenented network code. ---------------------------------------------------------------------- Blitzeloh92 · 2023-10-11 16:49 Use DynDns. e.g. duckdns. Create a duckdns domain and install the IP updater according to their guides on your server. Then point your own domain to that duckdns domain. On your server you wont need nginx for a game server, as most games use ports that others dont use. Just port forward the port your game needs in your router settings to the device if using ipv4 or directly use duckdns with ipv6. Then your friends can enter yourdomain.com to join the game. ---------------------------------------------------------------------- Derf0293 · 2023-10-11 17:27 Stream uses raw tcp/udp from what I understand. I'm going to try it out with a L4D2 server tonight, I've been looking for a similar solution as my DMZ vlan is a nightmare. ---------------------------------------------------------------------- blizznwins · 2023-10-11 17:38 Jesus the answers here are all over the place. You want to look for DynDNS, that is the proper solution for your problem. ---------------------------------------------------------------------- Derf0293 · 2023-10-11 17:47 Yeah really the solution here seems to be a dynamic DNS service. While the proxy is theoretically possible using nginx streams the only problem you're solving with that would be having to memorize port/address pairs where with nginx you could set up individual subdomains. If you're just running a simple server from your home for a few friends though this is absolutely overkill. ---------------------------------------------------------------------- ElevenNotes · 2023-10-11 18:04 haproxy would be the better choice as a TCP proxy ---------------------------------------------------------------------- Derf0293 · 2023-10-11 18:13 Yeah everyone got on the bandwagon to say nginx is HTTP/s only, which isn't true. Dynamic DNS is the way to go for sure. ---------------------------------------------------------------------- Derf0293 · 2023-10-11 18:57 I'm not splitting hairs on what's better, HA proxy has a lot to bring to the table too and is probably easier to set up out of the box. ---------------------------------------------------------------------- ElevenNotes · 2023-10-11 18:59 I exclusively use haproxy for TCP and traefik for UDP and nginx for HTTP. haproxy has better stats and health for TCP streams of all sorts than the other two from my experience. ---------------------------------------------------------------------- Derf0293 · 2023-10-11 19:13 Updated my reply with an edit detailing how to do it, this is certainly possible, tested it and it seems to be working with very little latency impact. ---------------------------------------------------------------------- Derf0293 · 2023-10-11 19:36 Glad to see they're still kicking, I started my career playing with HAProxy nearly 10 years ago, nginx definitely leaves a lot to be desired on the non-http front especially considering a lot of the more advanced features aren't included by default in many of the default package managers and don't even get me started on apache. ---------------------------------------------------------------------- ElevenNotes · 2023-10-11 19:47 keepalived as well, old stuff is still useful today. ---------------------------------------------------------------------- Derf0293 · 2023-10-11 19:53 One of these days I'm going to set up a proxy chain apache -> nginx -> HAProxy -> zookeeper -> keepalive -> caddy -> some random js library -> AWS alb -> azure app gw -> GCP GLB -> nodered -> lightbulb ---------------------------------------------------------------------- Derf0293 · 2023-10-11 20:46 A dedicated VPN will require a static IP as well. The correct solution here is to use a Dynamic DNS service. You could then point nginx or whatever tcp proxy or vpn at the domain provided by the dyndns provider. Tailscale or whatever the modern hamachi equivalent is is probably going to be the easiest solution though. ---------------------------------------------------------------------- geekafy · 2023-10-11 23:29 I personally use cloud flare with a subdomain that points to my home. I use decliner (https://developers.cloudflare.com/dns/manage-dns- records/how-to/managing-dynamic-ip-addresses/) to automatically update my DNS on that subdomain and it’s been working great flawless behind my firewall and NGINX reverse proxy. You can even use it to update multiple domains as well at the same time. Hope this helps ---------------------------------------------------------------------- zarlo5899 · 2023-10-12 04:23 you could use nginx to do this but a ssh tunnel would be better ---------------------------------------------------------------------- AleG911 · 2023-10-12 14:15 You could also do it with some sort of VPN (Wireguard or Tailscale)+ Iptables.