nginx tomcat负载配置

1.添加两个tomcat应用, 分别是server1, server2

  修改server1和server2的端口号, 避免重复这里设置为18080, 18081

2. 修改nginx.conf配置

  vim /usr/local/nginx/conf/nginx.conf

  在http{}里面新增配置, 这里使用轮询的方式, 当然还是IP哈希, UR哈希等方式

  upstream tomcats {
    server 服务ip:18080;
    server 服务ip:18081;
  }

  在server{}中新增配置 

  location / {
    proxy_pass http://tomcats;
  }

  继续配置静态资源, 静态资源目录自己创建, expires 10d表示客户端缓存10天, 也可以设置成10h表示10小时, 具体的时间根据自己需要设置.

  location ~ .*.(html|htm|gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ {
    root /usr/local/nginx-static/resources;
    expires 10d;
  }

3.执行wq退出并保存

4.cd到/usr/local/nginx/sbin目录执行./nginx -s reload重新加载, 配置文件生效

5. 访问服务器ip,默认nginx的端口是80,这时会跳转到tomcat默认页

如果要看到负载的效果, 可以将tomcat下webapps下的ROOT项目里面的index.jsp随便修改点类容便可以看到效果了.

原文地址:https://www.cnblogs.com/yaoximing/p/6070011.html