I actually wanted to get this load balanced, but I always feel that this thing is not easy, today Saturday idle nothing is finally determined to engage him, but did not expect this thing so simple, really is not my surprise simple (I now accompany is the simplest kind of). The amount is not as difficult as I imagined.
Again this record to prevent later forget, in go everywhere look for.
Nginx
Benefits, open source, simple, support for most platforms
Download the compression pack http://nginx.org/en/download.html from the official website first
I'm using nginx-1.8.1 this version of 1.22MB (really small)
Unzip it.
There's probably two problems here.
First, the configuration how to match
Two, how does this thing get up
First look how to match
It's still very simple to configure this thing.
The configuration file that you just downloaded is not configured (config file in conf/nginx.conf)
Open with sublime (most NB Notepad, stronger than notepad++, throw editplus 100 Street)
It should be commented out that the configuration file starts with #.
Mainly look at http{} This curly brace inside the thing,
Where we need to match only HTTP server{} this parenthesis inside
upstream a.com {#服务器集群名字 server192.168.0.110:8001weight=1, #服务器配置 weight is the weight, the larger the weight, the greater the probability of distribution. Server192.168.0.110:8002weight=1; } Server {Listen8088; #这个是Nginx监听的端口号 server_name localhost; #这个是服务器的名字 The two add up is to accompany play after the address of the visit localhost:8088 hard to refresh and see the effect of load balancing
Location/{proxy_pass http://a.com; #这个和第一行的对应Proxy_set_header Host $host; Proxy_set_header X-real-IP $remote _addr; Proxy_set_header X-forwarded-For $proxy _add_x_forwarded_for; } error_page - 502 503 504/50x.html; Location= /50x.html {root html; } }
The above configuration is copied directly, the configuration file of the server this piece of cover out on the line
In a moment of emphasis
upstream a.com { #服务器集群名字 server 192.168. 0.110:8001 weight=1; #服务器配置 weight is the weight, the greater the weight, the greater the probability of distribution. Server 192.168. 0.110:8002 weight=1; }
This configuration is not in the initial time,
Server This is the address of a server that needs load balancing, my site is deployed in the virtual machine on my computer, this IP address is the IP address of the virtual machine
If you don't have a virtual machine, you can use a local address.
Configuration complete
Start
Configuration is actually very simple, I started this piece to make me do not want to, I started to encounter problems, but just can't find the problem where
Start has two premise, the first you configure the port number, can not be occupied by other processes, second, your configuration file can not have a problem.
Because my configuration is I copy, so I did not look closely, the result of binding server when I was in front of the server address a number of a #
And then you can't get up, the problem is not an error.
CMD to find the extracted file
You can get up straight nginx.exe.
All I see on the Internet is using start Nginx to start with this method.
Start Nginx can also be started but if there is a problem, it will not show, so I am the egg ache why is not out of it.
The error above is that my 80 is occupied.
If there's no problem, we should get up now.
Then visit http://localhost:8088/and refresh to see the effect.
Anyway, mine's all right.
Use Nginx for load balancing on your own computer