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. mongodb集群故障转移实践

    简介 NOSQL有这些优势: 大数据量,可以通过廉价服务器存储大量的数据,轻松摆脱传统mysql单表存储量级限制. 高扩展性,Nosql去掉了关系数据库的关系型特性,很容易横向扩展,摆脱了以往老是纵向 ...

  2. zookeeper配置

    原文链接:https://www.cnblogs.com/yuyijq/p/3438829.html 前面两篇文章介绍了Zookeeper是什么和可以干什么,那么接下来我们就实际的接触一下Zookee ...

  3. Codeforces Round #419 (Div. 2)(B)差分数组

    传送门:Problem B https://www.cnblogs.com/violet-acmer/p/9721160.html 题意: Karen有n个关于煮咖啡的食谱,每个食谱都有个煮咖啡的最适 ...

  4. (母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  5. TCP的代码

    视频已经发布,这里是所有的代码仅供参考. TCP服务器: MainWindow里面的代码: using System; using System.Collections.Generic; using ...

  6. scala面向对象.高阶函数,柯里化,Actor编程简介

    1.定义一个类 class Person{ //用val修饰的变量是只读属性,有getter但是没有setter val id ="111" //用var修饰的变量既有getter ...

  7. Codeforces 264 B. Good Sequences

    B. Good Sequences time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  8. Rime中州韵导入极点五笔词库(附:自制词库)

    前言 之前写了一篇文章,[输入法]Rime-中州韵 基本设置 附:官方定制指南,其中导入词库这一块引用其它博主的文章,最近发现那个工具链接已经过期了,参考了百度贴吧的说明,不要直接使用工具去导入会更好 ...

  9. Linux 4.10.8 根文件系统制作(三)---制作yaffs文件系统

    这里直接用的是韦东山提供的工具. yaffs文件系统是专门用于nandflash的文件系统 我们前面已经下载了yaffs 的源码,也做了文件系统目录的构建. 在yaffs2的源码目录中有一个utils ...

  10. 【BZOJ4827】【HNOI2017】礼物

    强省HN弱省HA……(读作强省湖南弱省蛤 原题: 我的室友最近喜欢上了一个可爱的小女生.马上就要到她的生日了,他决定买一对情侣手 环,一个留给自己,一 个送给她.每个手环上各有 n 个装饰物,并且每个 ...