tomcat+nginx/apache

                 nginx
         /             |           \                     
          tomcat1      tomcat2  tomcat3          
http {   
     ...
    upstream tomcat{
             server 192.168.1.246:8080;
             server 192.168.1.246:8081;
             server 192.168.1.246:8082;
    }

    server {
         ...
        location = / {
                     root html;
                     index  index.html index.htm;
        }

        location ~ \.(gif|jpg|png|js|css)$ {
                     root html;
        }

        location ~ \.jsp$ {
                     proxy_pass http://tomcat;
        }
        ...
    }    
}    

curl http://192.168.1.247
curl http://192.168.1.247/index.jsp

apache整合tomcat
为什么要整合apache 与 tomcat?
1. 提升对静态文件的处理性能
2. 利用Web服务器来做负载均衡以及容错
3. 无缝的升级应用程序

方法一: JK方式

apache:
    # yum install httpd httpd-devel -y
    # tar xf tomcat-connectors-1.2.42-src.tar.gz
    # cd tomcat-connectors-1.2.42-src/native/
    # ./configure --with-apxs
    # make && make install
    # cd ../conf
    # cp  httpd-jk.conf  /etc/httpd/conf.d/
    # cp uriworkermap.properties workers.properties /etc/httpd/conf
    # vim /etc/httpd/conf.d/httpd-jk.conf
        JkWorkersFile conf/workers.properties           #定义线程的文件
        JkMountFile conf/uriworkermap.properties    #定义uri和线程的映射关系的文件
    # sed -r '/^#|^!|^$/d' /etc/httpd/conf/uriworkermap.properties 
        /*.jsp=balancer                                                #jsp网页由哪个线程处理
        /jk-manager=jk-manager
        /jk-status=jk-status
    # sed -r '/^#|^!|^$/d' /etc/httpd/conf/workers.properties 
        worker.list=jk-status
        worker.jk-status.type=status
        worker.jk-status.read_only=true
        worker.list=jk-manager
        worker.jk-manager.type=status
        worker.list=balancer
        worker.balancer.type=lb
        worker.balancer.error_escalation_time=0
        worker.balancer.max_reply_timeouts=10
        worker.balancer.balance_workers=node1,node2
        worker.node1.reference=worker.template
        worker.node1.host=192.168.10.12
        worker.node1.port=8009
        orker.node1.lbfactor=1
        worker.node1.activation=A
        worker.node2.reference=worker.template
        worker.node2.host=192.168.10.13
        worker.node2.port=8009
        orker.node2.lbfactor=1
        worker.node2.activation=A
        worker.template.type=ajp13
        worker.template.socket_connect_timeout=5000
        worker.template.socket_keepalive=true
        worker.template.ping_mode=A
        worker.template.ping_timeout=10000
        worker.template.connection_pool_minsize=0
        worker.template.connection_pool_timeout=600
        worker.template.reply_timeout=300000
        worker.template.recovery_options=3
    # systemctl restart httpd
方法二:
 http_proxy
需要mod_proxy模块支持

猜你喜欢

转载自blog.csdn.net/qq_43377292/article/details/86494223