tomcat配置及nginx反代至tomcat(二)


所有测试均在同一台主机:172.16.52.60

添加定义虚拟主机就是定义Host,appBase相当于httpd的DocumentRoot


vim /usr/local/tomcat/conf/server.xml

<Engine name="Catalina" defaultHost="localhost">


      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->


      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- This Realm uses the UserDatabase configured in the global JNDI
             resources under the key "UserDatabase".  Any edits
             that are performed against this UserDatabase are immediately
             available for use by the Realm.  -->
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>


      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">


        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->


        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />


      </Host>
      <Host name="www.a.com"  appBase="/myapp2"
            unpackWARs="true" autoDeploy="true">
     </Host>
      <Host name="www.b.com"  appBase="/myapp3"
            unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="remote_access_log" suffix=".txt"
               pattern="%h %l %u %t %{Referer}i %{User-Agent}i MSISDN=%{x-up-calling-line-id}i  &quot;%r&quot; %s %b   " 
                 />


<context path="/testapp" docBase="testapp" reloadable="true">
        </context>
     </Host>
    </Engine>



mkdir -pv /myapp2/ROOT/{lib,classes,WEB-INF,META-INF}

mkdir -pv /myapp3/ROOT/{lib,classes,WEB-INF,META-INF}

cp /myapp3/ROOT/{lib,classes,WEB-INF,META-INF} /myapp3/testapp -r

vim /usr/local/webapps/myapp/index.jsp 
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>JSP Test Page</title>
</head>
<body>
<% out.println("hello world");
%>
</body>
</html>


访问测试:http://www.a.com:8080

                    http://www.b.com:8080/testapp

                

nginx 配置:

server {
    listen       80;
    server_name  localhost;


    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;


    location / {

        proxy_pass http://www.b.com:8080/testapp;
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    
    location  ~*  \.(jsp|do)$ {
      proxy_pass http://www.b.com:8080;
    }


访问测试:http:172.16.52.60

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值