一,nginx反向代理
环境
步骤一: 部署后端Web 服务器web1和web2:以web1为例:
yum -y install gcc pcre-devel openssl-devel
yum -y install gcc pcre-devel openssl-devel
tar -xf nginx-1.10.3.tar.gz
cd nginx-1.10.3
useradd -s /sbin/nologin nginx
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module
make
make install
mv nginx-1.1* /usr/local/nginx/
ln -s /usr/local/nginx/sbin/nginx /sbin/
nginx
netstat -antulp |grep nginx
echo "192.168.1.100" > /usr/local/nginx/html/index.html
二,安装nginx,修改配置,添加服务器池,实现反向代理功能
1,安装Nginx
yum -y install gcc pcre-devel openssl-devel
cd nginx-1.10.3
useradd -s /sbin/nologin nginx
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module
make & make install
ln -s /usr/local/nginx/sbin/nginx /sbin/
nginx
netstat -antulp | grep nginx
2,修改Nginx配置文件
vim /usr/local/nginx/conf/nginx.conf
35 #使用upstream定义后端服务器集群,集群名称随意(如webserver)
36 #使用server定义集群中服务器的IP和端口
37 upstream webserver {
38 server 192.168.1.100:80;
39 server 192.168.1.200:80;
40 }
41
... ...
52 location / {
53 proxy_pass http://webserver;
54 #通过proxy_pass将用户的请求转发给webserver集群
nginx -s reload
三,客户端访问测试
http://192.168.0.2/ 访问测试刷新出现不同的页面,配置成功!!
配置upstream服务器集群池属性
vim /usr/local/nginx/conf/nginx.conf
37 upstream webserver {
38 server 192.168.1.100 weight=1 max_fails=1 fail_timeout=30;
39 server 192.168.1.200 weight=2 max_fails=2 fail_timeout=30;
40 server 192.168.1.101 down;
41 }
42 #weight设置服务器权重值,默认值为1
43 #max_fails设置最大失败次数
44 #fail_timeout设置失败超时时间,单位为秒
45 #down标记服务器已关机,不参与集群调度
配置upstream服务器集群的调度算法
vim /usr/local/nginx/conf/nginx.conf
37 upstream webserver {
38 ip_hash;
39 #通过ip_hash设置调度规则为:相同客户端访问相同服务器
40 server 192.168.1.100 weight=1 max_fails=1 fail_timeout=30;
41 server 192.168.1.200 weight=2 max_fails=2 fail_timeout=30;
42 server 192.168.1.101 down;
43 }
# nginx -s reload
客户端使用浏览器访问代理服务器测试轮询效果
# curl http://192.168.0.2 //使用该命令多次访问查看效果
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
二 ,TCP/UDP调度器
================================================================================================