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

另外一台:
http://192.168.195.133:8080/examples/index.html

nginx的访问:

原文地址:http://blog.51cto.com/4925054/2060572

时间: 2024-07-31 08:22:58

nginx 配置tomcat 实现负载均衡的相关文章

Nginx 服务器 之Nginx与tomcat实现负载均衡

  本文讲解我们如何使用Nginx做反向带服务器,实现nginx与tomcat服务器集群做负载均衡. 一.nginx与tomcat实现负载均衡 1.在/usr/local/ngnix/conf  创建文件 nginx-tomcat.conf 文件内容: user  nobody; worker_processes  2; events {        worker_connections  1024;     } http{    # upstream 配置一组后端服务器,     # 请求转

Tomcat(五):nginx/httpd + tomcat及负载均衡tomcat

*/ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hljs-comment, .hljs-template_comment, .diff .hljs-header, .hljs-javadoc { color: #998; font-style: italic; } .hljs-keyword, .css .rule .hljs-keyword, .h

Nginx配置upstream实现负载均衡及keepalived实现nginx高可用

(原文链接:http://www.studyshare.cn/blog-front//blog/details/1159/0 ) 一.准备工作 1.准备两个项目,发布到不同的服务器上,此处使用2个虚拟机发布了两个项目分别为:http://192.168.28.128:8081, http://192.168.28.129:8081 2.在两个虚拟机上都安装好nginx 二.配置upstream 1.在任意一台虚拟机上所安装的nginx的nginx.conf配置文件中配置upstream如下: 以

nginx+keepalived+tomcat+memcache负载均衡搭建小集群

最近一段时间一直在研究高可用高并发负载均衡分布式集群等技术,先前发布了lvs基于网络第四次协议搭建的小集群,现在用空刚好搭建了一个基于nginx搭建的小集群. 我准备了四台机器,情况如下 机器名称 机器IP 安装软件 角色 虚拟ip 描述 vmm01 192.168.252.11 Nginx.keepalived Nginx主机 192.168.252.200 反向代理到tomcat1和tomcat2 vmm04 192.168.252.14 Nginx.keepalived Nginx备机 主

LNMT架构部署:Linux+Nginx+Mysql+Tomcat(负载均衡,动静分离)

环境描述:虚拟机准备两台,一台作为nginx服务器+mysql服务器,IP为:192.168.55.129:另外一台作为2台Tomcat服务器,IP为:192.168.55.130.客户端发来请求,首先由nginx处理,如果为静态内容直接由nginx响应,将结果直接给客户端:如果为动态内容,则由nginx反代至后端的Tomcat服务器. 在IP为192.168.55.129的服务器上安装和配置nginx关闭防火墙和selinux [[email protected] ~]# systemctl

Nginx配置upstream实现负载均衡

Nginx可以配置代理多台服务器,当一台服务器宕机之后,仍能保持系统可用. 具体配置过程如下: 1. 在http节点下,添加upstream节点. upstream linuxidc {       server 10.0.6.108:7080;       server 10.0.0.85:8980; } 2.  将server节点下的location节点中的proxy_pass配置为:http:// + upstream名称,即"http://linuxidc". location

nginx配置+虚拟主机+负载均衡+反向代理

nginx启动+控制+配置文件 /usr/local/nginx/nginx    #启动 /usr/local/nginx/nginx -s reload    #重新加载配置文件,不需重启nginx进程 ##nginx.conf配置文件详解 nginx的配置文件相比apache,比较清晰.简单,大致分为几块: main events    {     .... } http    {     ...     upstream PROJECT_NAME    {        ##负载均衡服务

windows+nginx+memcached+tomcat做负载均衡

首先,我们明确目标,做Tomcat集群的目的是为了提供更高的负载能力,把访问均摊到不同的服务器上. 直观地来说,就是访问test.localhost.com时,nignx会随机将访问请求分发到tomcat1,tomcat2,为了保持session同步,使用memcached去管理session. 为此我们准备的配置清单是: windows x 1 nginx x 1 memcached x 1 tomcat x 2 mysql x 1 部署的架构图如下: 首先,我准备了一个Java Web项目.

Nginx+Keepalived+Tomcat+MySQL负载均衡& 通过nginx调度器访问Tom

目录第一部分 环境准备第二部分 部署调度器-搭建Nginx+Keepalived(双机热备)第三部分 部署服务器池-搭建Tomcat第四部分 搭建Mysql数据库第五部分 案例应用 第一部分 环境准备 一:Nginx+keepalived服务器两台(调度器,双机热备)系统:Linux-CentOS7.4IP地址:192.168.40.15192.168.40.16软件需求:nginx安装包(nginx-1.13.9.tar.gz)Keepalived安装包(keepalived-1.4.2.ta