nginx 負載均衡配置

yum或者源碼安裝nginx,在nginx/conf/vhosts下新建配置文件test.conf(前提是在主配置文件中nginx.conf增加include hosts/*.conf)

upstream test {

    ip_hash;

    server 192.168.31.100(服務器1IP);

    server 192.168.31.101(服務器2IP);

}

#IP後可支持權重,weight=2等


     server {

            listen 80;

            server_name bbs.aaa.cn;#定義域名用於訪問


            location / {

                proxy_pass      http://test/; #爲上面upstream 定義的別名

                proxy_set_header Host   $host;

                proxy_set_header X-Real-IP      $remote_addr;

                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            }

        }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章