Professional Documents
Culture Documents
About RoseHosting
https://www.rosehosting.com/blog/set-up-nginx-load-balancing/ 1/5
8/26/2021 How To Setup Nginx Load Balancing - RoseHosting
We need Nginx web server installed on the VPS. Run the following command to
install Nginx
vim /etc/nginx/sites-available/yourdomain.com.conf
and append the load balancing configuration at the top of the file
upstream loadbalancer {
server vps1.yourdomain.com;
server vps2.yourdomain.com;
server vps3.yourdomain.com;
You should have Nginx installed and listening on port 80 on all servers listed above.
server {
location / {
proxy_pass http://loadbalancer;
This configuration will equally distribute all incoming traffic across the three servers
(vps1.yourdomain.com, vps2.yourdomain.com, vps3.yourdomain.com). Nginx can be
also configured to distribute the traffic more efficiently. It comes with balancing
https://www.rosehosting.com/blog/set-up-nginx-load-balancing/ 2/5
8/26/2021 How To Setup Nginx Load Balancing - RoseHosting
7. Weight Balancing
We can use this option to specify the proportion of the traffic distributed to each of
the servers we listed in the upstream.
For example:
upstream loadbalancer {
8. Max Fails
If you use the default Nginx settings, it will send data to the servers even if they are
down. We can use the Max fails option to prevent such cases.
upstream loadbalancer {
9. IP Hash Balancing
With this method, the visitors will be always sent to the same server. So, if a visitor
received the content of vps1.yourdomain.com, it will be always transferred to that
server unless the servers are down or inaccessible.
upstream loadbalancer {
ip_hash;
server vps1.yourdomain.com;
server vps2.yourdomain.com;
https://www.rosehosting.com/blog/set-up-nginx-load-balancing/ 3/5
8/26/2021 How To Setup Nginx Load Balancing - RoseHosting
Of course you don’t have to Set up Nginx Load Balancing if you use one of our Nginx
VPS Hosting services, in which case you can simply ask our expert Linux admins to
setup Nginx load balancing for you. They are available 24×7 and will take care of your
request immediately.
PS. If you liked this post, on How To Set Up Nginx Load Balancing, please share it
with your friends on the social networks using the buttons on the left or simply leave
a reply below. Thanks.
david
December 21, 2016 | Reply
Nice tutorial
Thank you
admin
December 21, 2016 | Reply
Pingback: Physical server vs Virtual server: All you need to know – RoseHosting.com
Blog
Leave a Comment
https://www.rosehosting.com/blog/set-up-nginx-load-balancing/ 4/5
8/26/2021 How To Setup Nginx Load Balancing - RoseHosting
Name *
Email *
Save my name, email, and website in this browser for the next time I comment.
+
four
=
five
Post Comment
https://www.rosehosting.com/blog/set-up-nginx-load-balancing/ 5/5