一、當一個服務器不能滿足大量用戶的請求是,你可能需要用nginx爲你的請求分發到不同的機器上,可以通過nginx來配置不同服務器可以承載不同的請求量。
1.安裝: apt-get install nginx
2.配置文件路徑: /usr/share/nginx/nginx.conf
3.啓動: nginx -c nginx.conf
假設你要將nginx配置到a.host.com下面,並且你有b.host.com:8000和c.host.com:8000兩臺機器做業務服務程序配置如下:
events {
worker_connections 1024; ## Default: 1024
}
http{
upstream a.host.name{
server b.host.com:8000 weight=1 fail_timeout=2s max_fails=2;
server c.host.com:8000 weight=2 fail_timeout=2s max_fails=2;
}
server {
listen 8080;
server_name a.host.com ;
location / {
proxy_pass http://a.host.com;
proxy_redirect default;
proxy_connect_timeout 3s;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
以上的配置會將a.host.com:8080收到的請求分別安裝權重weight分發到b.host.com:8000和c.host.com:8000兩臺服務器上,fail_timeout–分發到server的超時時間,max_fails最多重試次數。