Understanding nginx (proxying, reverse proxying, load balancing)

A look into the less talked about of nginx.

Osita Chibuike
May 23, 2018 · 3 min read
Image for post
Image for post


Many think of Nginx as just a web server, yep it’s a web server, and so much more, Nginx is first and foremost a proxy engine, and load balancing server mechanism, which is capable of working as a web server using whichever preprocessor server you’d like, be it uWSGI, php-fpm etc.


Before getting up and running with nginx, it’s usually important (but not compulsory) that you meet the following conditions,

  • You have an understanding of what a web server is in general
  • You’ve used a computer before. 😏


The first scenario and struct we are going to check out is the concept and term of proxying. In general, terms, proxying is simply having one server position in front of another and have all request going to the second server go through the first server.

Load balancing

Load balancing is another problem nginx has been uniquely positioned to solve, it’s built to handle a lot of requests and if we have several servers running our project, we can balance the load between them using upstreams, load balancing is broad, therefore we are going to dive deep a little but not too much.

  • least_conn : Specifies that new connections should always be given to the backend that has the least number of active connections. This can be especially useful in situations where connections to the backend may persist for some time.
  • ip_hash : This balancing algorithm distributes requests to different servers based on the client’s IP address. The first three octets are used as a key to deciding on the server to handle the request. The result is that clients tend to be served by the same server each time, which can assist in session consistency.
  • hash : This balancing algorithm is mainly used with memcached proxying. The servers are divided based on the value of an arbitrarily provided hash key. This can be text, variables, or a combination. This is the only balancing method that requires the user to provide data, which is the key that should be used for the hash


Where are many other things we can achieve using nginx, this is pretty much just the tip of the iceberg. Setting up web servers and proxy servers can usually be a bit of a hassle, but it doesn’t have to.


Legobox logs

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store