What is a proxy server?

A proxy server is a server that holds the information of original servers in it. It acts as the front block for the client request. Whenever a client makes an HTTP request, it can directly go the application server. But, if the application server is written in a programming language, you need a translator that can turn the application response into a client-understandable response. Common Gateway Interface (CGI) does the same thing. For Go, we can run a simple HTTP server and it can work as a normal server (no translation required). So, why are we using another server called Nginx? We are using Nginx because it brings a lot of things into the picture.

The benefits of having a proxy server (Nginx):

  • It can act as a load balancer
  • It can sit in front of cluster of applications and redirect HTTP requests
  • It can serve a filesystem with a good performance 
  • It streams media very well

If the same machine is running multiple applications, then we can bring all those under one umbrella. Nginx can also act as the API gateway that can be the starting point for multiple API endpoints. We will see about a specially dedicated API gateway in the next chapter, but Nginx can also work as one. Refer to the following diagram:

If you see, the illustration client is talking directly to Nginx instead of the ports where other applications are running. In the diagram, Go is running on port 8000 and other applications are running on different ports. It means the different servers are providing different API endpoints. If the client wishes to call those APIs, it needs to access three ports. Instead, if we have Nginx, it can act as a proxy server for all three and simplifies the client request-response cycle.

Nginx is also called an upstream server because it serves the requests from the other server. From the illustration, a Python app can request an API endpoint from a Go app smoothly.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.40.189