nginx
来源:互联网 发布:帝国cms 搜索代码 编辑:程序博客网 时间:2024/05/20 17:40
反向代理:
访问nginx的ip和端口,由nginx根据请求的url解析去转发给后台不同的工程去做出处理和相应;
测试说明:
配置两个域名,解析域名指向同一台nginx服务器192.168.25.168(用来模拟公网ip),用户访问不同的域名显示不同的网页内容。两个域名是www.sian.com.cn和www.sohu.com模拟项目分布,即每个项目都有两个服务器做负载:配置服务器192.168.25.178:8080和192.168.25.188:8080各发布一个tomcat给www.sian.com.cn;配置服务器192.168.25.198:8080和192.168.25.208:8080各发布一个tomcat给www.sohu.com;
upstream tomcat1 {
server 192.168.25.168
:8080; #指向不同的工程的访问地址及端口,相应的请求会转发至此;- server 192.168.25.178:8080 ;
}
server {
listen 80; #监听端口,nginx对外发布服务的端口;
server_name www.sina.com.cn; #访问本节点的域名/会被本节点监听并转发的域名;
location / {
proxy_pass http://tomcat1; #代理地址,指向了上面定义的upstream,注意保持名称一致;
index index.html index.htm;
}
}
upstream tomcat2 {
server 192.168.25.188:8080;
server 192.168.25.208:8080;
}
server {
listen 80;
server_name www.sohu.com;
location / {
proxy_pass http://tomcat2;
index index.html index.htm;
}
}
负载均衡的权重配置方式:
说明: 这里简单记录三种方式,其他配置权重发方式可搜索整理;
1、轮询(默认)
每个请求按时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除;
2、weight
指定轮询几率,weight和访问比率成正比,用于后端服务器性能不均的情况;默认值为1;
upstream tomcat1 { server 192.168.25.168:8080 weight = 2; server 192.168.25.178:8080 weight = 3; }
3、ip_hash
每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题。
upstream tomcat1 {
ip_hash;
- server 192.168.25.168:8080;
server 192.168.25.178:8080;}
0 0
- nginx
- Nginx
- Nginx
- Nginx
- Nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- nginx
- Nginx
- nginx
- nginx
- nginx
- nginx
- leetcode 104. Maximum Depth of Binary Tree
- Lucene初探之索引过程分析(一)
- Struts2 环境搭建
- HashMap、weakHashMap、LinkedHashMap和TreeMap四者区别与联系
- 内核链表
- nginx
- 序列长度 差分约束
- 《Linux内核分析》MOOC课程第五次实验作业
- C语言——数组名、取数组首地址的区别(一)
- 第二次作业HUFF_ENC与huff_dec的编码调试
- Java关键字final、static使用总结
- PyCharm 2016.2.1 注册码[亲测可用]
- UnityEditor<三>自定义窗口 案例2
- poj 3984