nginx tomcat負載配置

1.添加兩個tomcat應用, 分別是server1, server2css

  修改server1和server2的端口號, 避免重複這裏設置爲18080, 18081html

2. 修改nginx.conf配置nginx

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

  在http{}裏面新增配置, 這裏使用輪詢的方式, 固然仍是IP哈希, UR哈希等方式vim

  upstream tomcats {
    server 服務ip:18080;
    server 服務ip:18081;
  }緩存

  在server{}中新增配置 tomcat

  location / {
    proxy_pass http://tomcats;
  }服務器

  繼續配置靜態資源, 靜態資源目錄本身建立, expires 10d表示客戶端緩存10天, 也能夠設置成10h表示10小時, 具體的時間根據本身須要設置.app

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

3.執行wq退出並保存

4.cd到/usr/local/nginx/sbin目錄執行./nginx -s reload從新加載, 配置文件生效

5. 訪問服務器ip,默認nginx的端口是80,這時會跳轉到tomcat默認頁

若是要看到負載的效果, 能夠將tomcat下webapps下的ROOT項目裏面的index.jsp隨便修改點類容即可以看到效果了.

相關文章
相關標籤/搜索