Install Nginx Proxy
I also want to point a domain name and an SSL certificate to the game server. We can add settings inside our server.js which is being run by NodeJS to manage this, but it is very common to use a proxy instead for this purpose. We can use Nginx. Nginx will be able to manage proxying for all your domain names and SSL certificates for this server, in case you ever want to have several websites running on it.
Check if Nginx is installed
No, then install it with
sudo apt install nginx
Now check its version
Now check it's status
sudo service nginx status
Visit http://[your ip address]
Delete the file /etc/nginx/sites-enabled/default
Create a new file called /etc/nginx/sites-enabled/minigames
Add this script
1 2 3 4 5 6 7 8
Test it by visiting again http://[your ip address]
Look at errors, how it is polling, and not creating a proper socket.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Test nginx configuration is ok,
sudo service nginx restart
And visit again http://[your ip address]
It should be perfect without any errors.
As an extra measure, to ensure that the game can only be played via the Nginx proxy, we can also block access to port 3000 from the internet but not locally on the server.
iptables -A INPUT -p tcp -s localhost --dport 3000 -j ACCEPT iptables -A INPUT -p tcp --dport 3000 -j DROP iptables -L