nginx跟tomcate集群的配置

搭建集群使用的nginx和tomcate版本

下载好nginx-1.8.0,开启nginx

在浏览器测试出现下图,服务启动成功

针对tomcate进行分离需要注意两点

1.配置tomcate的环境变量

2对tomcate进行分群操作

以下是我的nginx配置文件

    tcp_nopush on; #防止网络阻塞
    tcp_nodelay on; #防止网络阻塞
   fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_buffer_size 64k; 
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    gzip on; #开启gzip压缩输出
    gzip_min_length 1k; #最小压缩文件大小
    gzip_buffers 4 16k; #压缩缓冲区
    #gzip_http_version 1.1; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
    gzip_comp_level 2; #压缩等级
    gzip_types text/plain application/x-javascript text/css application/xml;
    #压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。
    gzip_vary on;
    #gzip  on;
  upstream mysvr {
#ip_hash;# 每个请求按访问ip的hash结果分配,这样每个访客固定访问一个后端服务器,可以解决session的问题 
    #weight参数表示权值,权值越高被分配到的几率越大
  server    127.0.0.1:18080  weight=1;#服务器配置   weight是权重的意思,权重越大,分配的概率越大。  
        server    127.0.0.1:28080  weight=2; 
    }


    server {
        listen       10011;
        server_name  192.168.10.23;
        #charset koi8-r;
        large_client_header_buffers 4 16k;
        client_max_body_size 300m;
        client_body_buffer_size 128k;
        proxy_connect_timeout 600;
        proxy_read_timeout 600;
        proxy_send_timeout 600;
        proxy_buffer_size 64k;
        proxy_buffers   4 32k;
        proxy_busy_buffers_size 64k;
        proxy_temp_file_write_size 64k;

        #access_log  logs/host.access.log  main;
location = /favicon.ico {
                log_not_found off;
                access_log off;
        }
        location / {
            root   html;
            index  index.html index.htm;
            proxy_set_header        X-Real-IP       $remote_addr;
     #proxy_set_header        Host            $host;
            #proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_pass http://mysvr; 
        }
        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;
    #    }
    #}
然后就是对tomcate8080默认端口的修改注意要改三处

1.将默认的8005改成别的

<Server port="8006" shutdown="SHUTDOWN">

2将默认的8080端口改成别的

 <Connector port="10080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />

3将默认的8009改成别的

 <Connector port="8010" protocol="AJP/1.3" redirectPort="8443" />

最后需要注意的是一定要配置tomcate的环境变量针对分群的!

需要注意因为使用nginx进行分配,所以要先访问nginx默认端口,再根据请求,进行转发分配,



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值