nginx 配置tomcat 实现负载均衡

简介:

环境:
准备三台机械: 两台安装tomcat 一台安装nginx;
安装步骤省略;
tomcat一台的IP:http://192.168.195.132:8080
另一台tomcat一台的IP:http://192.168.195.133:8080
nginxIP:http://192.168.195.134
主要:
nginx的配置文件nginx.conf:

#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;
 
    #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;
 
    upstream myServer{  
      server 192.168.195.132:8080 weight=1;  #weight权重 权重越大访问的概率越大

      server 192.168.195.133:8080 weight=2;  
    } 
 
    #gzip  on;
 
    server {
        listen       8080;
        server_name  192.168.195.134;
 
        #charset koi8-r;
 
        #access_log  logs/host.access.log  main;
 
       location / {  
            proxy_pass http://myServer;  #注意 http://后面的名字需要与  upstream myServe 的一致

            proxy_redirect default;  
        }  
 
        #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;
    #    }
    #}
 
}




分别启动两台tomat 访问路径如:
http://192.168.195.132:8080/examples/index.html
图片.png
另外一台:
http://192.168.195.133:8080/examples/index.html
图片.png

nginx的访问:

图片.png













本文转自yunlielai51CTO博客,原文链接:http://blog.51cto.com/4925054/2060572,如需转载请自行联系原作者


相关实践学习
部署高可用架构
本场景主要介绍如何使用云服务器ECS、负载均衡SLB、云数据库RDS和数据传输服务产品来部署多可用区高可用架构。
负载均衡入门与产品使用指南
负载均衡(Server Load Balancer)是对多台云服务器进行流量分发的负载均衡服务,可以通过流量分发扩展应用系统对外的服务能力,通过消除单点故障提升应用系统的可用性。 本课程主要介绍负载均衡的相关技术以及阿里云负载均衡产品的使用方法。
相关文章
|
16天前
|
移动开发 前端开发 JavaScript
前端vue2、vue3去掉url路由“ # ”号——nginx配置(一)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
49 0
|
17天前
|
JavaScript 前端开发 应用服务中间件
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
angular引入包、路由权限配置、打包问题与nginx配置问题(简单部署)
24 0
|
16天前
|
前端开发 JavaScript 应用服务中间件
前端vue2、vue3去掉url路由“ # ”号——nginx配置(二)
前端vue2、vue3去掉url路由“ # ”号——nginx配置
47 0
|
1天前
|
应用服务中间件 nginx
nginx配置集群轮训策略
nginx配置集群轮训策略
9 0
|
2天前
|
安全 网络协议 应用服务中间件
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
一文读懂HTTPS⭐揭秘加密传输背后的原理与Nginx配置攻略
|
3天前
|
IDE Java 应用服务中间件
JDK1.6.0+Tomcat6.0的安装配置(配置JAVA环境)
JDK1.6.0+Tomcat6.0的安装配置(配置JAVA环境)
14 1
|
3天前
|
网络协议 Java 应用服务中间件
HTTP协议与Tomcat在IJ中配置
本文是对自己学习JavaWeb学习的笔记的总结,添加了一些自己的东西,然后进行一次复盘,并加深一下学习的理解和印象.其中内容主要包括对http协议的详细介绍,java常见服务器的初步介绍,以及IJ旧版和新版的tomcat服务器的配置图解教程
|
10天前
|
应用服务中间件 PHP nginx
php如何实现检测nginx配置的正确性
请确保在执行此操作时,PHP有足够的权限来执行Nginx命令和访问Nginx配置文件。另外,将上述代码嵌入到您的应用程序中时,要注意安全性,以防止潜在的命令注入攻击。
50 3
|
13天前
|
运维 负载均衡 Cloud Native
Serverless 应用引擎产品使用之在Serverless 应用引擎中,使用云原生网关的情况下,SLB(负载均衡器)和证书配置如何解决
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
22 1
|
16天前
|
安全 应用服务中间件 网络安全
linux_nginx中添加ssl配置(open ssl)
linux_nginx中添加ssl配置(open ssl)
25 1