Nginx+tomcat 实现负载均衡和动静分离
来源:互联网 发布:淘宝怎么上代购保健品 编辑:程序博客网 时间:2024/06/05 00:39
怎么下载和安装nginx/tomcat就不说了,谈谈在刚开始配置时最容易让人模糊的地方。
1.配置动静分离和负载均衡,注意,upstram、server都是在http{}下面的。
upstream t1.test.com {
server 192.168.235.1:8080 weight=1 max_fails=2 fail_timeout=30s;
}
其中,红色标注定义的服务器组的名字,后续通过改名字制定服务器组。
server {
listen 80;
#server
server_name t1.test.com;
location / {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://t1.test.com;
}
#配置Nginx动静分离
location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
root /data/www;
#expires定义用户浏览器缓存的时间为3天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力.
expires 3d;
}
}
特别注意,蓝色标注的是指域名,就是通过访问http://t1.test.com 将使用该server定义。后面红色标注,指的是使用upstream中定义的服务器组。这样,访问http://t1.test.com域名的所有请求都会被server t1.test.com处理。
2.理解了upstream的使用方法,负载均衡就不是问题了,weight表示权重,max_fails=2 fail_timeout=30s这两个参数是指,30s内请求失败2次就不会再访问该server了。fail_timeout时间过后才继续访问,这是容错的一种处理,服务器如果恢复了,还是能继续使用。完整的配置如下
upstream t1.test.com {server 192.168.235.1:8080 weight=1 max_fails=2 fail_timeout=30s; }upstream t2.test.com {server 192.168.235.1:8081 weight=1 max_fails=2 fail_timeout=30s; }upstream all.test.com {server 192.168.235.1:8080 weight=1 max_fails=2 fail_timeout=30s;server 192.168.235.1:8081 weight=1 max_fails=2 fail_timeout=30s; }server {listen 80;#server server_name t1.test.com;location / {proxy_connect_timeout 3;proxy_send_timeout 30;proxy_read_timeout 30;proxy_pass http://t1.test.com;}#配置Nginx动静分离 location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {root /data/www;#expires定义用户浏览器缓存的时间为3天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力.expires 3d;}}server {listen 80;#server server_name t2.test.com;location / {proxy_connect_timeout 3;proxy_send_timeout 30;proxy_read_timeout 30;proxy_pass http://t2.test.com;}#配置Nginx动静分离 location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {root /data/www;#expires定义用户浏览器缓存的时间为3天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力.expires 3d;}}server {listen 80;#server server_name all.test.com;location / {proxy_connect_timeout 3;proxy_send_timeout 30;proxy_read_timeout 30;proxy_pass http://all.test.com;}#配置Nginx动静分离 location ~ .*\.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {root /data/www;#expires定义用户浏览器缓存的时间为3天,如果静态页面不常更新,可以设置更长,这样可以节省带宽和缓解服务器的压力.expires 3d;}}
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx + Tomcat 实现动静分离负载均衡
- Nginx+Tomcat 动静分离实现负载均衡
- Nginx+Tomcat 动静分离实现负载均衡
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx+Tomcat 实现动静分离、负载均衡
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx + Tomcat 动静分离实现负载均衡
- Nginx+tomcat 实现负载均衡和动静分离
- Nginx与tomcat 实现负载均衡和动静分离
- 第15周项目 3.2 OJ
- IOS之禁用UIWebView的默认交互行为
- SVN 出现 database disk image is malformed
- 浅析郭婶儿子--LitePal框架(二)
- 获取一组radio中checked的value值
- Nginx+tomcat 实现负载均衡和动静分离
- HDU 5139 Formula(数据离线处理)
- Effective C++ Item02 Note
- 代理模式笔记
- Combination Sum II
- objective-c 数字对象 NSNumber
- 数据挖掘的一些课程
- Uploadify 控件上传图片 + 预览
- 获取一组radio的checked的value值