Nginx配置反向代理和负载均衡

3 篇文章 0 订阅
2 篇文章 0 订阅

1.配置反向代理

编辑配置nginx 配置文件,在安装目录下找到nginx.conf 配置如下代码

反向代理:proxy_pass  ip:port[uri];

   server {
        listen    80;
        server_name  www.360.com;
        location /{
                root /mnt;
                autoindex on;
        }
       }

    server {
        listen       80;
        server_name  www.sxthenhao.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }
        location /ooxx.go {
        proxy_pass http://192.168.227.12/;  //反向代理服务器

        }
}

其中server 配置的是多个服务端,listen 配置的是需要请求的端口,server_name则是配置访问的域名, location 配置过滤规则

location 映射(ngx_http_core_module)
	location [ = | ~ | ~* | ^~ ] uri { ... }
	location URI {}:
		对当前路径及子路径下的所有对象都生效;
	location = URI {}: 注意URL最好为具体路径。
		精确匹配指定的路径,不包括子路径,因此,只对当前资源生效;
	location ~ URI {}:
	location ~* URI {}:
		模式匹配URI,此处的URI可使用正则表达式,~区分字符大小写,~*不区分字符大小写;
	location ^~ URI {}:
		不使用正则表达式
	优先级:= > ^~ > ~|~* >  /|/dir/

/loghaha.html
/logheihei.html
^/log.*html$

2.配置负载均衡

(1)在nginx.config文件中配置

   upstream bula{
        server 192.168.227.12;
        server 192.168.227.13;

   }

其中server 是需要负载均衡的服务器  bula 为随意起的名字

(2)将服务器的llocation 的转发proxy_pass 接口改为 定义的负载均衡服务器组的名字

(3)禁止会话保持

keeplive_timrout 设置为0

 

重启nginx 加载配置文件
[root@node01 conf]# service nginx reload

访问 实验


第一次访问

第二次访问

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值