码迷,mamicode.com
首页 > 系统相关 > 详细

linux环境下nginx + tomcat 负载均衡

时间:2020-06-18 21:31:42      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:cte   stream   The   logs   pass   shell   error   har   err   

修改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 负载均衡

标签:cte   stream   The   logs   pass   shell   error   har   err   

原文地址:https://www.cnblogs.com/fyusac/p/13159542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!