linux环境下nginx + tomcat 负载均衡

Posted 枫叶艾辰

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux环境下nginx + tomcat 负载均衡相关的知识,希望对你有一定的参考价值。

修改nginx 的配置文件/etc/nginx/nginx.conf

http {
    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  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    # 负载均衡模块,负责网站的负载均衡功能和节点的健康检查
    # 实例中127.0.0.1:8080和8081分别是两个tomcat的ip地址和访问端口号
    upstream myservers{
           server 127.0.0.1:8080 weight=1;
           server 127.0.0.1:8081 weight=1;
    }
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /usr/share/nginx/html;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
        	# 请求转发模块,将请求转发到指定的服务器上
                proxy_pass http://myservers;
        }

        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
        
    }

修改tomcat的访问端口: ./conf/server.xml

将其中一个tomcat的以下两个端口分别该为:8006,8081,另一个tomcat的配置文件使用默认值,即仍是

<Server port="8005" shutdown="SHUTDOWN">
    
<Connector port="8081" protocol="HTTP/1.1"
   .../>

https://www.cnblogs.com/xiaowenshu/p/10099119.html

以上是关于linux环境下nginx + tomcat 负载均衡的主要内容,如果未能解决你的问题,请参考以下文章

Linux下搭建一个nginx+2tomcat负载均衡环境(转)

nginx+tomcat实现负载均衡以及session共享(linux centos7环境)

Linux 下 tomcat基于nginx做负载均衡

Linux CentOS搭建JDK+Mysql+Tomcat+Nginx负载均衡环境      

linux下:nginx+tomcat实现负载均衡

开发人员学Linux:CentOS7编译安装Nginx并搭建Tomcat负载均衡环境