This is more of a guide for doing reverse proxying via nginx for a TCP server on port 80 using Nginx. I am writing this
because when I was trying to figure out how to do this, all I had was Nginx’s TCP Load Balancing article
(which ended up being enough), but just having a how-to like would’ve been nice.
Before you get started
A couple of things to note:
You must be using Nginx version 1.9 or higher. Currently you can get 1.9 through the mainline branch.
You cannot be running HTTP servers on the same machine over port 80. Running the TCP server on port 80 is achieved easily by removing the HTTP section of the nginx config.
Other than that, you need to make sure to get rid of the top-level http directive within your nginx.conf. This can usually be found at /etc/nginx/nginx.conf. If you still
have the http directive, it will block this from working. I would recommend replacing your nginx.conf file with something similar to what is below.
As shown within the above config, this can easily be changed to provide load balancing. All you have to do is change the stream directive to something like this: