nginx負載均衡配置

1、準備工作

nginx-1.6.0.tar.gz

httpd-2.2.23.tar.gz


Director Server:10.0.2.201

Real Server:10.0.2.203

Real Server:10.0.2.204


2、Director Server上配置nginx

# yum install -y pcre pcre-devel

# tar zxvf nginx-1.6.0.tar.gz

# cd nginx-1.6.0

# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module

# make && make install


3、配置nginx的反向代理

# vim /usr/local/nginx/conf/nginx.conf

修改server_name爲域名或者IP地址,並添加以下內容

location / {

            proxy_pass http://10.0.2.204;

            root   html;

            index  index.html index.htm;

}

# /usr/local/nginx/sbin/nginx 


4、配置nginx負載均衡

# vim /usr/local/nginx/conf/nginx.conf

upstream myserver{

server 10.0.2.203:80 weight=1;

server 10.0.2.204:80 weight=1;

ip_hash;

location / {

proxy_pass http://myserver;

proxy_next_upstream http_500 http_502 http_503 error timeout invalid_header;

include /usr/local/nginx/conf/proxy.conf;

# vim /usr/local/nginx/conf/proxy.conf

proxy_redirect off;

proxy_set_header Host $host;#

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

client_body_buffer_size 128k;

proxy_connect_timeout 90;

proxy_send_timeout 90;

proxy_read_timeout 90;

proxy_buffer_size 4k;

proxy_buffers 4 32k;

proxy_busy_buffers_size 64k;

proxy_temp_file_write_size 64k;

# /usr/local/nginx/sbin/nginx 


5、Real Server安裝http

# tar zxvf httpd-2.2.23.tar.gz

# cd httpd-2.2.23

# ./configure --prefix=/usr/local/apache2

# make && make install

# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd

# vim /etc/init.d/httpd

修改文件,在文件中'#!/bin/sh'後面加入下面兩條規則:

#!/bin/sh

#

# chkconfig: 2345 85 15

# description: Apache is a World Wide Web Server

#

# chkconfig --add httpd

# chkconfig --list httpd

# service httpd start


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