windows tomcat nginx session(当一台tomcat关闭后)
在windows下作nginx负载均衡测试。
nginx的配置文件如下:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include
mime.types;
default_type application/octet-stream;
upstream localhost {
server 127.0.0.1:8080 weight=1 max_fails=2
fail_timeout=30s;
server 127.0.0.1:8081 weight=1 max_fails=2
fail_timeout=30s;
}
sendfile
on;
keepalive_timeout 65;
server
{
listen
80;
server_name localhost;
listen
80;
server_name
localhost;
location
/{
proxy_pass
http://localhost;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
}
error_page 500 502 503
504 /50x.html;
location = /50x.html {
root html;
}
}
}
遇到这个问题,搜索网络, 发现网上也有人遇到同样的问题, 问题描述如下:
用了nginx负载均衡后,在两台tomcat正常运行的情况下,访问http://localhost
速度非常迅速,通过测试程序也可以看出是得到的负载均衡的效果,但是我们试验性的把其中一台tomcat(server
localhost:8080)关闭后,再查看http://localhost,发现反应呈现了一半反映时间快,一半反映时间非常非常慢的情况,但是最
后都能得到正确结果。
然后我又把关闭的那吧tomcat实例恢复,此时再访问http://localhost,又可以很快的访问,负载均衡也运行正常了!郁闷!
分析怀疑可能是nginx将一半的左右的请求仍然发到了宕掉的tomcat实例上了,然后由于转发到宕掉的tomcat没有反映,nginx又重新分发到其它实例上处理。
但是这个时间也太长了。当有一台宕机后,访问http://localhost有时候会现了大概30s左右的响应时间,非常郁闷!
增加这么几个参数:
proxy_connect_timeout
300;
proxy_send_timeout
300;
proxy_read_timeout
300;
问题解决,主要是proxy_connect_timeout
这个参数, 这个参数是连接的超时时间。 我设置成1,表示是1秒后超时会连接到另外一台服务器。
现在贴出NGINX的配置如下,供后来人参考:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log
notice;
#error_log logs/error.log
info;
#pid
logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include
mime.types;
default_type application/octet-stream;
upstream localhost {
#ip_hash;
server 127.0.0.1:8081;
server 127.0.0.1:8080;
}
#log_format main '$remote_addr
- $remote_user [$time_local] "$request" '
#
'$status $body_bytes_sent "$http_referer" '
#
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log
main;
sendfile
on;
#tcp_nopush
on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server
{
listen
80;
server_name localhost;
listen
80;
server_name
localhost;
location
/{
proxy_pass
http://localhost;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For
$proxy_add_x_forwarded_for;
proxy_connect_timeout
1;
proxy_read_timeout
1;
proxy_send_timeout
1;
}
#charset koi8-r;
#access_log
logs/host.access.log main;
#error_page
404
/404.html;
# redirect server error pages to the static page
/50x.html
#
error_page 500 502 503
504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on
127.0.0.1:80
#
#location ~ \.php$ {
#
proxy_pass
http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on
127.0.0.1:9000
#
#location ~ \.php$ {
#
root
html;
#
fastcgi_pass
127.0.0.1:9000;
#
fastcgi_index index.php;
#
fastcgi_param SCRIPT_FILENAME
/scripts$fastcgi_script_name;
#
include
fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document
root
# concurs with nginx's one
#
#location ~ /\.ht {
#
deny all;
#}
}
# another
virtual host using mix of IP-, name-, and port-based
configuration
#
#server
{
#
listen
8000;
#
listen
somename:8080;
#
server_name somename
alias another.alias;
# location /
{
#
root html;
#
index index.html index.htm;
# }
#}
# HTTPS
server
#
#server
{
#
listen
443;
#
server_name localhost;
#
ssl
on;
#
ssl_certificate
cert.pem;
#
ssl_certificate_key cert.key;
#
ssl_session_timeout 5m;
#
ssl_protocols SSLv2 SSLv3 TLSv1;
#
ssl_ciphers
ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#
ssl_prefer_server_ciphers
on;
# location /
{
#
root html;
#
index index.html index.htm;
# }
#}
}
windows tomcat nginx session(当一台tomcat关闭后)的更多相关文章
- Tomcat集群,Nginx集群,Tomcat+Nginx 负载均衡配置,Tomcat+Nginx集群
Tomcat集群,Nginx集群,Tomcat+Nginx 负载均衡配置,Tomcat+Nginx集群 >>>>>>>>>>>> ...
- Windows下nginx的启动,重启,关闭功能
@echo off rem 提供Windows下nginx的启动,重启,关闭功能 echo ==================begin======================== cls :: ...
- redis+tomcat+nginx session共享
http://www.cnblogs.com/zhrxidian/p/5432886.html系列课程 简洁明了 http://blog.csdn.net/grhlove123/article/det ...
- Windows server 2012 R2开机进入cmd,关闭后黑屏问题
原因分析: 因为自己在卸载IIS的时候,不小心卸载了.net framework,系统没有了图形界面(由完整模式Full变为了核心模式core),需要重新恢复.net framework4.5. 解决 ...
- Redis+Tomcat+Nginx集群实现Session共享,Tomcat Session共享
Redis+Tomcat+Nginx集群实现Session共享,Tomcat Session共享 ============================= 蕃薯耀 2017年11月27日 http: ...
- tomcat中session在两个webapp中实现共享
现在遇到一个需求就是要求完成简单的单点登录,通过在一个tomcat实例中放置两个webapps应用ROOT应用和CEO应用来完成在ROOT应用登录后,在CEO可以直接使用,而未在ROOT应用登录时,不 ...
- 高级运维(五):构建memcached服务、LNMP+memcached、使用Tomcat设置Session、Tomcat实现session共享
一.构建memcached服务 目标: 本案例要求先快速搭建好一台memcached服务器,并对memcached进行简单的添.删.改.查操作: 1> 安装memcached软件,并启动服务d ...
- tomcat redis session共享
编译redis所需要的序列化包 安装 gradle Linux & MacOS users Configure your PATH environment variable to includ ...
- Tomcat学习总结(10)——Tomcat多实例冗余部署
昨天在跟群友做技术交流的时候,了解到,有很多大公司都是采用了高可用的,分布式的,实例沉余1+台.但是在小公司的同学也很多,他们反映并不是所有公司都有那样的资源来供你调度.往往公司只会给你一台机器,因为 ...
随机推荐
- poj 2187 N个点中输出2点的最大距离的平方
旋转卡壳 Sample Input 40 00 11 11 0Sample Output 2 # include <iostream> # include <cstdio> # ...
- Rookey.Frame之菜单设置
在上一篇博文 Rookey.Frame企业级快速开发框架开源了 中我们介绍了Rookey.Frame极速开发框架的最新更新及开源介绍,后面慢慢介绍该框架的使用方法,本人文笔不好,写得不够好的地方请大家 ...
- CentOS7 之基础设置及常见操作命令
1.Host SMbus controller not enabled 解决方法: 在 /etc/modprobe.d/blacklist.conf 文件里添加 blacklist i2c_piix4 ...
- 异常类Exception(String message, Throwable cause)中的cause理解
这个在构造函数里面竟然有一个Throwable,感觉有些奇怪. 1. Throwable cause 这里cause要传一个Throwable的子类异常进去么? 是引起这个异常的异常,如果这个值是空值 ...
- thinkphp结合ajax实现统计页面pv的浏览量
统计pv量很常用,下面的代码用ajax实现的,使用ajax可以避免页面缓存造成的影响,只要客户端的js代码执行了就可以统计流量. 一共就两部 将下面代码放在要统计的html页面中,测试时把地址换成自己 ...
- jupyter notebook变量高亮
首先声明,anaconda安装的时候,一定要勾选“Add Anaconda to my PATH environment variable”! 否则会有一堆麻烦的问题,做了这一步就能自动添加好路径!不 ...
- [leetcode greedy]455. Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...
- BZOJ.2286.[SDOI2011]消耗战(虚树 树形DP)
题目链接 BZOJ 洛谷P2495 树形DP,对于每棵子树要么逐个删除其中要删除的边,要么直接断连向父节点的边. 如果当前点需要删除,那么直接断不需要再管子树. 复杂度O(m*n). 对于两个要删除的 ...
- [BZOJ3928/4048]Outer space invaders
[BZOJ3928/4048]Outer space invaders 题目大意: 有\(n(n\le300)\)个物品,第\(i\)个物品会在\(a_i\sim b_i\)时刻出现,且离你的距离为\ ...
- [BZOJ2716]天使玩偶
[BZOJ2716]天使玩偶 题目大意: 一个平面直角坐标系,坐标\(1\le x,y\le10^6\).\(n(n\le10^6)\)次操作,操作包含以下两种: 新增一个点\((x,y)\): 询问 ...