Nginx(web服务器)与Tomcat(应用服务器)搭建集群
Nginx作为互联网最常用的web服务器,高性能的HTTP和反向代理使它经常作为Tomcat集群的方案。Nginx官方只支持使用HTTP协议的集成,但是如果你想使用AJP协议集成,可以使用阿里开源的nginx_ajp_module。接下来我们使用HTTP的方式集成:
1.准备Nginx、Tomcat1、Tomcat2
Nginx下载并启动:http://nginx.org/en/download.html
nginx默认端口80,我这里为了方便也就不修改了,直接启动
server {
listen ;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page /50x.html;
location = /50x.html {
root html;
}
}

Tomcat下载并启动:https://tomcat.apache.org/download-80.cgi#8.5.43
tomcat由于是同一台机器,我这里修改了端口号,配置分别是:
<Server port="" shutdown="SHUTDOWN">
<Connector port="" protocol="HTTP/1.1" connectionTimeout="" redirectPort="" />
<Connector port="" protocol="AJP/1.3" redirectPort="" />
<Server port="" shutdown="SHUTDOWN"> <Connector port="" protocol="HTTP/1.1" connectionTimeout="" redirectPort="" />
<Connector port="" protocol="AJP/1.3" redirectPort="" />
修改好配置,把示列工程sample1放在tomcat1,sample2放在tomcat2里面,启动两个tomcat:


访问http://localhost:8081/sample1/

访问http://localhost:8082/sample2/

2.配置Nginx,将Nginx与Tomcat1、Tomcat2集成
Nginx集成可以使用HTTP方式,也可以使用AJP方式,这里使用的HTTP方式。
2.1修改nginx的目录下conf下nginx.conf配置
在http{}下面配置
#配置服务器1
upstream sample1{
server localhost:;
}
#配置服务器2
upstream sample2{
server localhost:;
}
在server{}下配置
#映射服务器1
location /sample1/ {
proxy_pass http://sample1;
}
#映射服务器2
location /sample2/ {
proxy_pass http://sample2;
}
重启nginx,再一次访问
http://localhost/sample1/

http://localhost/sample2/

3.负载均衡配置
在http{}下面配置
#负载均衡配置服务器群组
upstream sample1{
#实例1
server localhost: weight= max_fails= fail_timeout=30s;
#实例2
server localhost: weight= max_fails= fail_timeout=30s;
}
在server{}下配置
#映射服务器集群
location /sample1/{
proxy_pass http://sample1;
}
因为这里我们配置的两个项目是不同名称的,所以负载均和1:1时候,会有一个是无法访问。
在tomcat2里面把tomcat1里面的sample1复制过来,显示改为hello,tomcat2!
访问http://localhost/sample1/,不断刷新


Nginx(web服务器)与Tomcat(应用服务器)搭建集群的更多相关文章
- Nginx学习笔记(反向代理&搭建集群)
一.前言 1.1 大型互联网架构演变历程 1.1.1 淘宝技术 淘宝的核心技术(国内乃至国际的 Top,这还是2011年的数据) 拥有全国最大的分布式 Hadoop 集群(云梯,2000左右节点,24 ...
- 使用Nginx在windows和linux上搭建集群
Nginx Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器 特点:反向代理 负载均衡 动静分离… 反向代理(Reverse Pro ...
- Nginx 在 Linux 下安装与搭建集群
搭建集群图例 集群搭建图如下,为了简单一点,使用一个Nginx服务器+两个Tomcat服务器,省略数据库部分: 环境说明 Linux 为 CentOS 7.2 发行版 + Java jdk 1.8 + ...
- nginx+apache+mysql+php+memcache+squid搭建集群web环境
服务器的大用户量的承载方案 一.前言 二.编译安装 三. 安装MySQL.memcache 四. 安装Apache.PHP.eAccelerator.php-memcache 五. 安装Squid 六 ...
- apache和tomcat搭建集群
最近在学习简单的apache服务器和两个tomcat一起搭建集群,这里简单记录一下 1.准备工作 ①搭建一个可以运行的web项目 用maven搭建springmvc项目 ,只要将这里面的web.xml ...
- [link] 构建负载均衡服务器之一 负载均衡与集群详解
一.什么是负载均衡 首先我们先介绍一下什么是负载均衡: 负载平衡(Load balancing)是一种计算机网络技术,用来在多个计算机(计算机集群).网络连接.CPU.磁盘驱动器或其他资源中分配负载, ...
- Nginx+Tomcat搭建集群,Spring Session+Redis实现Session共享
小伙伴们好久不见!最近略忙,博客写的有点少,嗯,要加把劲.OK,今天给大家带来一个JavaWeb中常用的架构搭建,即Nginx+Tomcat搭建服务集群,然后通过Spring Session+Redi ...
- Windows7系统中nginx与IIS服务器搭建集群实现负载均衡
10分钟搭建服务器集群——Windows7系统中nginx与IIS服务器搭建集群实现负载均衡 分布式,集群,云计算机.大数据.负载均衡.高并发······当耳边响起这些词时,做为一个菜鸟程序猿无疑 ...
- 架构之路:nginx与IIS服务器搭建集群实现负载均衡(二)
[前言] 在<架构之路:nginx与IIS服务器搭建集群实现负载均衡(一)>中小编简单的讲解了Nginx的原理!俗话说:光说不练假把式.接下来,小编就和大家一起来做个小Demo来体会一下N ...
- 架构之路:nginx与IIS服务器搭建集群实现负载均衡(三)
参考网址:https://blog.csdn.net/zhanghan18333611647/article/details/50811980 [前言] 在<架构之路:nginx与IIS服务器搭 ...
随机推荐
- CentOS linux7 重置root密码
1.启动linux,进入grub,就是选择系统界面,选中系统按e进入编辑界面 2.找到linux16那一行,在末尾加上init=/bin/sh.按Ctrl+x,使用单用户模式启动4.mount -o ...
- JS原生上传大文件显示进度条-php上传文件
JS原生上传大文件显示进度条-php上传文件 在php.ini修改需要的大小: upload_max_filesize = 8M post_max_size = 10M memory_li ...
- configmap使用-完整的configmap文档
转发 https://www.jianshu.com/p/cf3e2218f283 转发 https://www.kubernetes.org.cn/3138.html 注意:configmap不用也 ...
- Ansible变量嵌套解析
有时候需要用到ansible的变量的嵌套解析,就是“变量中嵌套变量”.例子如下: 假设有一个外部传递的变量,system_code = CRM,而我们同时有一系列类似的变量,如: ABS_port=1 ...
- 【HANA系列】SAP HANA SQL获取字符串长度
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA SQL获取字符 ...
- Spring boot (一):入门篇
Spring boot 简介 Build Anything with Spring Boot:Spring Boot is the starting point for building all Sp ...
- 【Linux开发】linux设备驱动归纳总结(五):1.在内核空间分配内存
linux设备驱动归纳总结(五):1.在内核空间分配内存 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...
- C++学习笔记-继承
类之间可以建立联系,这就使得类可以有某种关系 类之间的关系 has-A:包含关系,一个类使用另一个已经定义好的类的数据 uses-A:使用关系,友元或者对象参数传递 is-A:是的关系,这就是继承,具 ...
- 登录进入Mysql数据库的几种方式
前提:连接进入mysql数据库 本机安装的myslq基础信息: host= "localhost", # 数据库主机地址:127.0.0.1 port=3306, # 端口号 us ...
- MSF魔鬼训练营-3.2.1活跃主机扫描
概要: msf的arp_sweep .udp_sweep模块 Nmap -sn使用ping探测 -PU -sn 使用UDP协议端口探测 msf模块 arp_sweep 常用 ipv6_mult ...