一、基础环境:
负 载 机:A机器: 192.168.71.223
后端机器1:B机器:192.168.71.224
后端机器2:C机器:192.168.71.226
需求: 1)访问A机器的8080端口,反向代理到B机器的8080端口; 访问A机器的8088端口,反向代理到C机器的8088端口; 访问http://192.168.71.223:8090/ios,反向代理到B机器http://192.168.1.102:8090/ios/ 2)访问A机器的80端口,负载均衡到后端的两台机器B和C的80端口
二、安装配置:
1、三个机器共同执行:
1)编译安装nginx yum install -y pcre* openssl* gcc gcc+ mkdir /opt/src && cd /opt/src wget http://nginx.org/download/nginx-1.8.0.tar.gz && tar -zxvf nginx-1.8.0.tar.gz && cd nginx-1.8.0 useradd www -M -s /sbin/nologin #添加www用户,其中-M参数表示不添加用户家目录,-s参数表示指定shell类型 vi /opt/src/nginx-1.8.0/auto/cc/gcc #CFLAGS="$CFLAGS -g" #将这句注释掉 取消Debug编译模式 大概在179行
./configure --prefix=/opt/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module #我们再配置下nginx编译参数 make && make install clean
2、机器A配置:
cd /opt/nginx/conf
vi nginx.conf
将配置改为:
worker_processes 2; events { worker_connections 65535; } http { include mime.types; default_type application/octet-stream; charset utf-8; log_format main '$http_x_forwarded_for $remote_addr $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_cookie" $host $request_time'; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; fastcgi_connect_timeout 3000; fastcgi_send_timeout 3000; fastcgi_read_timeout 3000; fastcgi_buffer_size 256k; fastcgi_buffers 8 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; client_header_timeout 600s; client_body_timeout 600s; client_max_body_size 100m; client_body_buffer_size 256k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 9; gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php; gzip_vary on; include vhosts/*.conf; }