tomcat+nginx+域名绑定+servlet

nginx同时是一个很强的反向代理server,可以用来跟tomcat做负载均衡集群,而且配置很简单,不过有个需要注意的地方:目前nginx跟后端server使用http1.0协议,不能keepalive,只能每次重新打开连接。需要关闭后端的keepalive,否则会产生大量后端的timewait状态的socket连接。
主要的是nginx的配置

<!-- lang: shell -->
server {
  listen          80;
  server_name     YOUR_DOMAIN;
  root            /PATH/TO/YOUR/WEB/APPLICATION;
  location / {
    index index.jsp;
  }
  location ~ \.do$ {
    proxy_pass              http://localhost:8080;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        Host $http_host;
  }                                                                                                       
  location ~ \.jsp$ {
    proxy_pass              http://localhost:8080;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        Host $http_host;
  }
  location ^~/servlets/* {
    proxy_pass              http://localhost:8080;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        Host $http_host;
  }
}

相关资料:
http://hillside.iteye.com/blog/559772
http://wiki.nginx.org/NginxJavaServers
http://wiki.nginx.org/HttpProxyModuleChs
http://www.360doc.com/content/10/1215/14/58597_78364548.shtml

你可能感兴趣的:(tomcat+nginx+域名绑定+servlet)