Nginx反向代理负载均衡

作者: admin 分类: Linux 发布时间: 2018-04-26 17:26 浏览:939 次    

1、安装nginx

[root@qunniao ~]# yum -y install nginx

2、修改配置

[root@qunniao ~]# vim /etc/nginx/nginx.conf
user nginx;
 worker_processes auto;
 error_log /var/log/nginx/error.log;
 pid /run/nginx.pid;
 events {  
        worker_connections 1024;
   }
 http { 
 server {
  listen 80 default_server; 
 location / { 
 proxy_pass http://webserver;
 } 
 }

#轮询

upstream webserver {
   server server1.lncs.net; 
   server server2.lncs.net;
 }

#ip_hash

upstream webserver {
        ip_hash;
        server srv1.example.com;
        server srv2.example.com;
   }

#权重

upstream webserver {
        server srv1.example.com weight=3;
        server srv2.example.com weight=1;
}

#最少连接

upstream webserver {
        least_conn;
        server srv1.example.com;
        server srv2.example.com;
        server srv3.example.com;
   }


 


温馨提示:如无特殊说明,本站文章均为作者原创,转载时请注明出处及相应链接!

发表评论