1.整体架构

本测试包括1个nginx,2个tomcat。整个系统架构如下。

Nginx下管理了静态资源,如jsp,css等。连接了2个tomcat,采用轮询访问的规则。

2.tomcat部署

本次测试中用了2个tomcat,其服务端口为8081、8082。在两个tomcat的webapps目录下部署war包。

3.Nginx配置

3.1配置服务器

# 注意,这里的server名字即org.tonny.balance不能带下划线,有下划线则不能访问

upstream org.tonny.balance {

server 127.0.0.1:8081 weight=1;

server 127.0.0.1:8082 weight=1;

}

3.2设置规则

# 不带数据的请求,包括restful风格的请求

location / {

proxy_pass   http://org.tonny.balance;

# root   html;

# index  index.html index.htm;

}

# 静态文件,从这里获取

location ~* \.(css|gif|png|jpeg|ico|svg)$ {

root D:/App/nginx/apache-tomcat-7.0.92_1/webapps/ROOT;

}

# jsp类型的请求,从这里走

location ~ \.jsp$ {

proxy_pass   http://org.tonny.balance;

}

3.3完整文件

#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;

proxy_buffer_size 128k;

proxy_buffers 32 128k;

proxy_busy_buffers_size 128k;

#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名字即org.tonny.balance不能带下划线

upstream org.tonny.balance {

server 127.0.0.1:8081 weight=1;

server 127.0.0.1:8082 weight=1;

}

server {

listen       80;

server_name  localhost;

#charset koi8-r;

#access_log  logs/host.access.log  main;

# 不带数据的请求,包括restful风格的请求

location / {

proxy_pass   http://org.tonny.balance;

# root   html;

# index  index.html index.htm;

}

# 静态文件,从这里获取

location ~* \.(css|gif|png|jpeg|ico|svg)$ {

root D:/App/nginx/apache-tomcat-7.0.92_1/webapps/ROOT;

}

# jsp类型的请求,从这里走

location ~ \.jsp$ {

proxy_pass   http://org.tonny.balance;

}

#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 ssl;

#    server_name  localhost;

#    ssl_certificate      cert.pem;

#    ssl_certificate_key  cert.key;

#    ssl_session_cache    shared:SSL:1m;

#    ssl_session_timeout  5m;

#    ssl_ciphers  HIGH:!aNULL:!MD5;

#    ssl_prefer_server_ciphers  on;

#    location / {

#        root   html;

#        index  index.html index.htm;

#    }

#}

}

4.测试验证

4.1tomcat验证

①在浏览器中输入:http://localhost:8081/index.jsp

②在浏览器中输入:http://localhost:8082/index.jsp

③启动nginx

输入命令:start nginx

在浏览器中输入:http://localhost/

刷新浏览器,会发现 “tomcat-test-2”字样会交替变换。

④请求部署项目

最终目的是通过nginx请求部署在tomcat中的项目

在浏览器中输入:http://localhost/suguo/cpu/list

5.文件下载

部署所用的包在https://github.com/oneqhw/spring-suguo

目录spring-suguo/src/main/resources/resource中可以下载到

名字nginx.zip,相应的sql建表语句也在这里。压缩文件中包含了nginx,tomcat,以及war包程序,解压后即可使用

转载于:https://www.cnblogs.com/supertonny/p/10587264.html

Nginx负载均衡配置相关推荐

  1. Nginx负载均衡配置和健康检查

    Nginx负载均衡配置和健康检查 注:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任. nginx的强大之处不必要我细说,当初第一次接触ngin ...

  2. nginx负载均衡配置-windows

    http://www.2cto.com/os/201302/191589.html nginx负载均衡配置-windows 虽然说windows上的nginx在官方文档中提到"仅作为测试&q ...

  3. Nginx负载均衡配置实例

    五.Nginx负载均衡配置实例 实现效果:访问 www.123.com/edu/a.html的时候,将请求平均分配到8080和8081端口. 准备工作: 1)准备两台Tomcat服务器(端口号为808 ...

  4. Nginx负载均衡配置实例详解

    负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的同学有所帮助哦. 负载均衡 先来简单了解一下什么是负载均衡,单从字面上的意思来理解就可 ...

  5. Nginx负载均衡配置实例详解(转)

    | 时间:2013-09-05 20:19:17 | 阅读数:810738 [导读] 负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的 ...

  6. Tomcat集群快速入门:Nginx负载均衡配置,常用策略,场景及特点

    Nginx负载均衡的配置,常用策略,场景,以及特点,放到这里是需要更细化的讲解,毕竟一期还没有做集群,而我们这一期做集群的时候,很多点要单独拿出来深入讲解,第一个轮询,默认的一个配置,简单也好理解,第 ...

  7. Nginx 负载均衡 配置全过程

    Nginx平台搭建:Nginx+mysql+php-fpm搭建高性能Nginx平台 前端Nginx:192.168.93.137 后端web1:192.168.93.138 后端web2:192.16 ...

  8. Nginx负载均衡配置策略

    转自:http://www.freeoa.net/osuport/cluster/nginx-load-equilibrium-configuration-strategy_1652.html Ngi ...

  9. nginx负载均衡配置,宕机自动切换方式

    拓展:https://blog.csdn.net/u011477914/article/details/84381509   nginx负载均衡,服务器集群配置,服务器挂机自动切换 (这篇文章写得也很 ...

  10. 超详细Linux -- nginx负载均衡配置

    Nginx 负载均衡应用配置 Nginx实现负载均衡的方式 1.轮询(默认) 每个请求按时间顺序逐一分配到不同的后端服务器,后端服务器宕机时,能被自动删除,且请求不会受影响. 2.weight权重 指 ...

最新文章

  1. Python——基础篇
  2. 在Eigrp做不等值路由的负载均衡
  3. Educational Codeforces Round 76 (Rated for Div. 2) F. Make Them Similar 折半搜索
  4. mysql日志管理_关于MySQL的日志管理(binlog)
  5. SpringCloud(二) 服务注册到Eureka
  6. stone 的 log4j配置详解
  7. zookeeper 进入客户端_Zookeeper基础知识简单介绍
  8. 从前端开发者看待用友建筑云移动端单点登录与报错原因
  9. 牛人自述模拟电路学习历程
  10. CheckMarx源代码安全测试工具
  11. python读取txt数据
  12. SPSS学习笔记(二)T检验
  13. nifi mysql hive_Nifi入门
  14. wjw的剪纸(DFS)
  15. 程序员如何避免面向监狱编程?避免踩雷!
  16. 李晋的YIM每日签名
  17. Java网络爬虫抓取新浪微博个人微博记录
  18. python战舰世界_当下三国杀高玩口中的收益论是否过时/错误,若是,如何正确从理论层面评价武将的强弱 若否 为何?...
  19. 国产软件不背黑锅,4款强大又实用的电脑软件,用了舍不得卸载
  20. 在微软(Microsoft)工作是怎样一番体验?

热门文章

  1. 黑客白皮书:如何成为一名黑客(附FAQ)
  2. wifi 性能 测试 android,WiFi性能测试app下载
  3. OSPF- P2P网络、NBMA网络和P2MP网络
  4. Html5网页录音,js录音mp3
  5. latex 首行不缩进,第二行开始缩进,悬挂缩进的LaTeX实现
  6. Unity il2cpp LinuxInterop_dlopen Error
  7. [Chatter] 为甚么要学Design Pattern
  8. 下载微信公众号中的视频的方法
  9. php堆栈是什么意思,如何理解什么是堆栈
  10. LPR基准利率BP是什么意思,银行利率bp是什么意思