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. mybatis返回部分字段为空的问题

    问题: 在数据库查询的时候可以正常返回值,在程序中只能返回一部分字段,其他字段为null. 错误原因: 将resultType改为resultMap https://www.cnblogs.com/i ...

  2. springboot静态资源处理

    转:https://blog.csdn.net/catoop/article/details/50501706 Spring Boot 默认为我们提供了静态资源处理,使用 WebMvcAutoConf ...

  3. 当input获取倒焦点的时候,获得输入内容

    描述:当用户点击输入框时,获取到他在input里输入的内容 $().keyup(function(){ $(this).val(); }) $(this).val()==this.value; $(t ...

  4. Windows 系统安装多个版本JDK, 修改环境变量不生效

    1. 前提: 1) 配置环境变量: JAVA_HOME 2) 配置PATH: 添加%JAVA_HOME%\bin 2. 解决: 1) 确保最新的, 你希望使用的JDK, 配置在PATH的字符串的前面, ...

  5. java基础基础总结----- 关键字、标识符、注释、常量和变量、运算符、语句、函数、数组(三)

    Java语言基础组成:关键字.标识符.注释.常量和变量.运算符.语句.函数.数组 一.标识符 标识符是在程序中自定义的一些名称,由大小写字母[a-zA-Z],数字[0-9],下划线[ _ ],特殊字符 ...

  6. grafana-zabbix部署和使用

    grafana-zabbix安装 官网安装介绍地址:https://grafana.com/plugins/alexanderzobnin-zabbix-app/installation 下载地址:h ...

  7. P3594 [POI2015]WIL-Wilcze doły

    P3594 [POI2015]WIL-Wilcze doły 题目描述 给定一个长度为n的序列,你有一次机会选中一段连续的长度不超过d的区间,将里面所有数字全部修改为0.请找到最长的一段连续区间,使得 ...

  8. Hadoop基础-HDFS的读取与写入过程剖析

    Hadoop基础-HDFS的读取与写入过程剖析 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 本篇博客会简要介绍hadoop的写入过程,并不会设计到源码,我会用图和文字来描述hdf ...

  9. db nosql redis / Redis Sentinel

    s Redis基础原理和日常操作方法 http://itsm.cns*****.com/kindeditor/img/20170527/759128afca564051b491e6a51a5bad40 ...

  10. Nginx 学习笔记(二)Web 服务启用 HTTP/2

    个人网站提升为HTTP2.0协议,加速访问 一.条件 1.openssl的版本必须在1.0.2e及以上 2.nginx的版本必须在1.9.5以上 二.编译安装 1.openssl 编译安装 (1)开始 ...