1、准备两个Tomcat

首先在Linux机器上部署两个Tomcat,端口分别为80和8080

2、分别部署测试应用

在两个tomcat下分别部署同一个应用testapp,很简单,就是在页面显示当前系统时间:

testapp

--WEB-INF

--web.xml

--index.jsp

index.jsp内容:

<html>
<body>
<center>Now time is :<%=new java.util.Date() %></center>
</body>
</html>

3、启动两个Tomcat

查看是否能正常运行

4、修改nginx配置

1)配置监控端口

server {
    listen 8080;
    ......
}

2)配置服务器集群

upstream testapp {  #服务器集群名字
    server    120.78.144.82:8080  weight=2;
    server    120.78.144.82:80  weight=1;
}

3)配置URL匹配路径

location /testapp {
    proxy_pass http://testapp;
    proxy_redirect default;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,
            X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    }

------------------------------------------------------------

5、修改配置后重启nginx

[root@iZwz95a6wosz6klzf7o6hcZ sbin]# pwd
/usr/local/nginx/sbin
[root@iZwz95a6wosz6klzf7o6hcZ sbin]# ./nginx -s reload

6、测试

关闭8080端口的Tomcat,如果仍能访问到testapp页面,则nginx配置成功。

#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 {
use epoll;
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #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 /gxxj/nginx/logs/access.log; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on;
#干线巡检的集群
upstream mobile_gxxj { #服务器集群名字
server 132.228.125.45:6001 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
#server 132.228.228.194:6003 weight=2;
}
#光网助手的集群
upstream mobile_gwzs {
server 132.228.228.194:6005 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。
} server {
listen 8080;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main;
location /ins/mobile/gxxj {
proxy_pass http://mobile_gxxj;
proxy_redirect default;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
location / {
proxy_pass http://132.228.237.107:6001;#主要是这里,这是tomcat1的端口和项目
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
#光网助手手机端代理
location /ins/mobile/cableCheck{
proxy_pass http://mobile_gwzs;
proxy_redirect default;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
#点温代理
location /jfxj {
proxy_pass http://mobile_gxxj;
proxy_redirect default;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
} #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;
# }
#} }

nginx配置集群的更多相关文章

  1. 【Nginx(三)】Nginx配置集群 负载均衡策略

    Nginx配置集群 负载均衡策略 一.安装环境 1.安装JDK8的环境,配置JDK8的环境变量 2.上传jar包demo-1.jar 和 demo-2.jar demo-1.jar 监听8080端口; ...

  2. 【Nginx(四)】Nginx配置集群 负载均衡策略

    1.Nginx常见的负载均衡策略 ip_hash (固定分发) 简介:根据请求按访问ip的hash结果分配,这样每个用户就可以固定访问一个后端服务器 场景:服务器业务分区.业务缓存.Session需要 ...

  3. nginx+tomcat集群配置(4)--rewrite规则和多应用根目录设定思路

    前言: nginx中有一块很重要的概念, 就是rewrite规则. 它会对URL进行修改, 然后进行内部的重定向. rewrite授予了nginx更多的自由, 使得后级服务的接入更加地方便. 本文将简 ...

  4. 图文解说:Nginx+tomcat配置集群负载均衡

    图文解说:Nginx+tomcat配置集群负载均衡 博客分类: appserver nginxTomcatUbuntuLinux网络应用  作者:niumd Blog:http://ari.iteye ...

  5. nginx+tomcat集群配置(1)---根目录设定和多后端分发配置

    前言: 对于javaer而言, nginx+tomcat集群配置, 已然成了web应用部署的主流. 大公司如此, 小公司亦然. 对于个人开发者而言, 资源有限, 往往多个web应用混部于一台服务器(云 ...

  6. 转】Nginx+tomcat配置集群负载均衡

    原博文出自于:http://blog.csdn.net/bruce_6/article/details/38228299         感谢! 相信很多人都听过nginx,这个小巧的东西慢慢地在吞食 ...

  7. 配置集群Nginx+Memcached+Tomcat集群配置

    上班之余抽点时间出来写写博文,希望对新接触的朋友有帮助.今天在这里和大家一起学习一下配置集群 1.   Nginx Nginx是通过将多个Web Server绑定到同一个IP地址下,以实现多个WebS ...

  8. nginx.conf 集群完整配置

    ###############################nginx.conf 集群完整配置############################### #user nobody; # user ...

  9. Nginx+Tomcat集群配置

    Nginx+Tomcat集群配置 一台虚拟机作为Nginx服务 两太虚拟机配置Tomcat+jdk环境 Nginx测试 启动: cd usr/local/nginx/sbin ./nginx ---& ...

随机推荐

  1. poj3114 Contries in War (tarjan+dijkstra)

    缩完点后对每次询问做dijkstra即可 #include<cstdio> #include<cstring> #include<algorithm> #inclu ...

  2. 自动生成Excel 报表工具类

    /** * 输出Excel文档 * * @param response * @param sheetName 文件名称 * @param firstCellTile 第一行的标题 * @param c ...

  3. vs2013配置opencv2.4.13

    此方法配置简单,方便易行,解压opencv2.4.13后得到opencv文件夹,进行如下步骤: 1.添加环境变量 用户变量,新建,变量名opencv,值D:\opencv\build 系统变量,Pat ...

  4. linux系统关闭IPv6的方式

    云服务器 ECS> Linux操作运维问题 > 应用配置 > linux系统关闭IPv6的方式 linux系统关闭IPv6的方式 IPv6被认为是IPv4的替代产品,它用来解决现有I ...

  5. Python基础【day02】:字符串(四)

    在Python中字符串本身有带很多操作,字符串的特性,不可以被修改 0.字符串常用功能汇总 1.字符串的定义 #定义空字符串>>> name=''#定义非空字符串 >>& ...

  6. System.Runtime.InteropServices.COMException:“服务器出现意外情况。 (异常来自

    .Net MVC导出Excel的时候,一直报错,如题.原因是因为福昕阅读器,这样设置 execl->点击文件>选项>加载项,选择com加载项,把祈福阅读器勾掉.

  7. 查看windows下指定的端口是否开放

    有时候会出现ip  ping的通   但是就是连接不上的情况.这时候我们需要检测一下这个端口是否被开放 netstat -ano -p tcp | find >nul && ec ...

  8. maven的隔离部署

    场景:比如说我们一个项目,在开发的时候是一套配置文件,在发布的时候又是一套配置文件.我们每次都要修改配置文件很烦有木有.所以,我们需要maven的这样的一个功能,就是隔离部署.就是说我们写好几套配置文 ...

  9. Hbase记录-Hbase调优参数

  10. 【JUC】JDK1.8源码分析之ReentrantReadWriteLock

    重入锁ReentrantLock是排他锁,排他锁在同一时刻仅有一个线程可以进行访问,但是在大多数场景下,大部分时间都是提供读服务,而写服务占有的时间较少.然而读服务不存在数据竞争问题,如果一个线程在读 ...