Tomcat一个请求的完整过程

Ng:(nginx)
upstream yy_001{ 

server 10.99.99.99:8080;
server 10.99.99.100:8080;
hash $**;
healthcheck_enabled;
healthcheck_delay 3000;
healthcheck_timeout 1000;
healthcheck_failcount 2;
healthcheck_send 'GET /healthcheck.html HTTP/1.0' 'Host: wo.com'
'Connection: close';
}
server { 

include base.conf;
server_name wo.de.tian;
...
location /yy/ { 

proxy_pass http://yy_001;
}复制

首先 dns 解析 wo.de.tian机器,一般是ng服务器ip地址,然后 ng根据server的配置,寻找路径为 yy/的机器列表,ip和端口,最后 选择其中一台机器进行访问。

下面为详细过程

  1. 请求被发送到本机端口8080,被在那里侦听的Coyote HTTP/1.1 Connector获得
  2. Connector把该请求交给它所在的Service的Engine来处理,并等待来自Engine的回应
  3. Engine获得请求localhost/yy/index.jsp,匹配它所拥有的所有虚拟主机Host
  4. Engine匹配到名为localhost的Host(即使匹配不到也把请求交给该Host处理,因为该Host被定义为该Engine的默认主机)
  5. localhost Host获得请求/yy/index.jsp,匹配它所拥有的所有Context
  6. Host匹配到路径为/yy的Context(如果匹配不到就把该请求交给路径名为”“的Context去处理)
  7. path=”/yy”的Context获得请求/index.jsp,在它的mapping table中寻找对应的servlet
  8. Context匹配到URL PATTERN为*.jsp的servlet,对应于JspServlet类
  9. 构造HttpServletRequest对象和HttpServletResponse对象,作为参数调用JspServlet的doGet或doPost方法
  10. Context把执行完了之后的HttpServletResponse对象返回给Host
  11. Host把HttpServletResponse对象返回给Engine
  12. Engine把HttpServletResponse对象返回给Connector
  13. Connector把HttpServletResponse对象返回给客户browser

发表评论

后才能评论