Hello,
I have been developing a multiplayer game for several months, it is built with WebGL and hosted on a website. The server is a linux server that I deploy via AWS GameLift. I recently added SSL to my site, and naturally began to get MixedContent errors in the console since my UnityTransport was not using secure websockets.
I ticked on Use Encryption within the UnityTransport component on my NetworkManager hoping it would be seamless integration but sadly I have spent countless hours trying to fix my whole setup due to the lack of support for wss.
I came across this thread where @simon-lemay-unity mentioned the following:
Set up a reverse proxy that will accept WSS traffic, pop the encryption, and forward it to your server unencrypted (and then do the reverse for all traffic coming from the server). Clients will think theyāre connecting to a secure server, but your actual server will not need to mess with certificates and such. Unfortunately, thatās not exactly a simple solution. Youāll need to spin up a machine at some cloud provider to act as the reverse proxy. And youāll still need to set up certificates on that machine (some cloud providers might make this easier though).
I have done exactly this. I built a node.js reverse proxy server that is hosted on a subdomain of my main website. Both my main website and the subdomain have SSL certificates. I have set up my nginx configuration for my subdomain such that when the index route / is hit, it routes traffic to the proxy server running on the same machine at port 8080:
server {
http2 on;
listen 443 ssl;
listen [::]:443 ssl;
server_name subdomain.mysite.com;
ssl_certificate ...
ssl_certificate_key ...
...
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}
I am able to successfully hit this proxy server which is hosted on the same machine as my backend api ā both from my local dev machine and the machine itself. I can hit it successfully with a variety of websocket tools including websocat, browser console, curl, etc. I cannot however hit this proxy server with Unity despite trying everything imaginable. It seems the UnityTransport doesnāt allow hostnames but rather only ip addresses, so I have to connect like this:
UnityTransport transport = NetworkManager.Singleton.GetComponent<UnityTransport>();
transport.UseWebSockets = true;
transport.UseEncryption = true;
transport.SetClientSecrets("subdomain.mysite.com"); //using the real domain
transport.SetConnectionData("000.000.000.000", 443); //using the real IP address
...
NetworkManager.Singleton.StartClient();
However time and time again I get Failed to connect to server. I have tried with the hostname instead of the IP, I have tried specifying the caCert from LetsEncrypt (r3, r6). I even put a direct log route in the nginx config to see if I could even hit that route from unity but I canāt. I can hit it via anything else, but not Unity. Verified several times that I have the right IP and port.
In summary, I cannot for the life of me get Unity to connect to the proxy server (to then establish an unencrypted websocket connection with the gameserver) after calling NetworkManager.Singleton.StartClient(). Iāve had direct unencrypted connections to GameLift-hosted server instances working for months, but as soon as I ticked encryption on, everything went to hell
. I think it has to do with the fact that I must supply an IP address instead of the hostname, to which the SSL cert is bound. If you try to supply the hostname as the transport connection address, youāll get invalid endpoint errors when calling StartClient.
Is there an established way to connect the UnityTransport to a proxy server that is hosted on a website with SSL?
Package Versions:
Netcode for Gameobjects: 2.2
Unity Transport: 2.4
