Nginx安裝及負載均衡配置

Nginx用源碼安裝需要先安裝依賴庫,比較麻煩,推薦用yum安裝

<1>Centos下執行 rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

<2>安裝

    yum -y install nginx

<3>配置Nginx負載均衡

   Nginx的配置文件爲nginx.conf,yum安裝的話,路徑爲/etc/nginx/nginx.conf.

   vi /etc/nginx/nginx.conf,

  在http裏邊添加

    upstream Elasticsearch{

      server   192.168.1.124:80;

      server     192.168.1.125:80;

     .........................

}

注意:upstream 不爲改爲其他的名字,必須是upstream,web_pool可以自己命名,server 也不能改名字  後邊的IP爲參加輪詢的服務器IP和端口號。注意後邊的;不能省略,否則會報錯


  server {

    lisiten  80; //nginx監聽的端口號;

    server_name  nginx_name;

      location / { 
        proxy_pass http://Elasticsearch; 
        proxy_set_header   Host             $host; 
        proxy_set_header   X-Real-IP        $remote_addr; 
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for; 
      }
   } 

}

    

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