windows/ubuntu using nignx for load Balancing
First, the implementation of Ubuntu
1, first install nginx server sudo apt-get install nginx
2, cd/etc/nginx/
Sudo Vim Sites-avaliables/default
①, add outside the server node:
Upstream Server_pool {
Server 192.168.0.88:80 weight=4 max_fails=2 fail_timeout=30s;
Server 192.168.0.89:80 weight=2 max_fails=2 fail_timeout=30s;
}
#HTTP Load Balancer module. upstream This field to set up a group of servers, you can put this field in the
As a separate entity in the Proxy_pass and fastcgi_pass directives, they can be servers that listen to different ports, and
It can also be a server that listens to both TCP and Unix sockets . The server can specify a different weight, which defaults to 1.
②, modifying the server node
server {
... ...
Location/{
Proxy_pass http://server_pool/;
# Determine the URL, port, or socketthat needs to be proxied .
Proxy_redirect off;
# If you need to modify the "location" and "Refresh" fields from the reply headers that came from the backend server , you can use this command
Set up.
Proxy_set_header X-real-ip $remote _addr;
# This directive allows you to redefine or add some fields to the request headers sent to the backend server. This value can be a literal, a variable, or a combination of them.
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
Proxy_set_header Host $host;
Proxy_next_upstream Error timeout Invalid_header http_500 http_502 http_503
http_504 http_404;
# determine under what circumstances the request will be forwarded to the next server:
#error-an error occurred while connecting to a server, sending a request, or reading an answer.
#timeout- A timeout occurred while connecting to the server, forwarding a request, or reading an answer.
#invalid_header-The server returned an empty or incorrect answer.
#http_500-The server returns the code.
#http_502-The server returns the 502 code.
#http_503-The server returns the 503 code.
#http_504-The server returns the 504 code.
#http_404-The server returns the 404 code.
#off- disables forwarding of requests to the next server.
}
③, restart nginx Server
Sudo Service Nginx Restart
Virtual Host Configuration: Configure http://root.com Virtual host
①,sudo cp/ect/nginx/sites-avaliables/default/etc/nginx/sites-avliables/root
②,sudo vim etc/nginx/sites-avliables/root
③, modifying the server node
/etc/nginx/nginx.conf
server {
Listen 80;
Root 80.com;
}
server {
Listen 8080;
Root 8080.com;
}
Apache Configure virtual Host: Configure http://root.com Virtual host
①,sudo cp/ect/nginx/sites-avaliable/default/etc/nginx/sites-avliable/root
②,sudo vim etc/nginx/sites-avliables/root
③, modifying configuration
1<virtualhost *:80>2 3 ServerAdmin [email protected]4 5ServerName Web.root.com6 7DocumentRoot/var/www/Root8 9<directory/>Ten One Options followsymlinks A - allowoverride None - the</Directory> - -<directory/var/www/root/> - + Options Indexes followsymlinks multiviews - + allowoverride None A atOrder Allow,Deny - - allow from all - -</Directory> - in - toscriptalias/cgi-bin//usr/lib/cgi-bin/ + -<directory "/usr/lib/cgi-bin" > the * allowoverride None $ Panax NotoginsengOptions +execcgi-multiviews +SymLinksIfOwnerMatch - theOrder Allow,Deny + A allow from all the +</Directory> - $ $ -Errorlog ${apache_log_dir}/error.Log
④,sudo ln-s/etc/apache2/sites-avaliable/root/etc/apache2/sites-avaliable/root;
⑤,sudo service apache2 restart
Second,Windows nginx.conf
1Worker_processes 4;2 3Upstream test.com{4 5Server 192.168.1.155;6 7Server 127.0.0.1:80;8 9 }Ten One A - server { - theListen 8080; - - server_name localhost; - + - + #CharSet koi8-r; A at - - #access_log Logs/host.access.log main; - -Root "e:/2016phpstudy/www"; - inLocation/ { - toIndex index.html index.htm index.php L.php; + - AutoIndex off; the * #where Jq_one corresponds to the cluster name set by upstream $ Panax NotoginsengProxy_pass http://test.com; - the #set the host header and client real address so that the server obtains the client's real IP + AProxy_set_header Host$host; the +Proxy_set_header X-real-ip$remote _addr; - $Proxy_set_header x-forwarded- for $proxy _add_x_forwarded_for; $ - - the}
Windows/ubuntu using NIGNX for load balancing