利用nginx做负载均衡
- round-robin:轮询。以轮询方式将请求分配到不同服务器上,默认
- least-connected:最少连接数。将下一个请求分配到连接数最少的那台服务器上
- ip-hash :基于客户端的IP地址。散列函数被用于确定下一个请求分配到哪台服务器上
nginx.conf
upstream myapp { #least_conn; #ip_hash; #server 192.168.10.29:80 weight=3; #值越大权重就越大 server 192.168.10.29:80; server 192.168.10.29:8090; } server { listen 8080; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http://myapp; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #root html; #root /Users/zhoutingze/vhost/8080; #index index.html index.htm index.php; #rewrite ^(.*)$ index.php/$1; #rewrite (.*) /index.php; }