tomcat多虚拟主机配置+nginx反向代理

1.tomcat 设置
<Engine name="Catalina" defaultHost="www.bbb.com">  #Engine默认主机defaultHost
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>
      </Realm>

      <Host name="www.aaa.com"  appBase="webapps"unpackWARs="true" autoDeploy="true">
        <Context path="/test" docBase="/data/test" reloadable="false" />
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhostA_access_log" suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />
      </Host>

      <Host name="www.bbb.com"  appBase="website"unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhostB_access_log" suffix=".txt"
               pattern="%h %l %u %t "%r" %s %b" />
      </Host>
    </Engine>

2.创建页面  
echo /usr/local/tomcat/webapps/ROOT/index.html >  /usr/local/tomcat/webapps/ROOT/index.html

mkdir /data/test  -p
echo /data/test/index.html >  /data/test/index.html
echo www.aaa.com/test/index.jsp > /data/test/index.jsp

mkdir /usr/local/tomcat/website/ROOT/
echo www.bbb.com/index.jsp > website/ROOT/index.jsp

  

3.nginx设置   yum install nginx
http {
    server {
        listen       80;
        server_name  www.magedu.net;

        location / {
           proxy_pass http://www.aaa.com:8080;   # 全部反向代理
           index   index.html;
        }
    }
    server {
        listen       80;
        server_name  www.zzhz.com;
		
        location / {
           root  /usr/share/nginx/html;
           index index.html;
        }
        location ~* \.(jsp|do)$ {              # 动静分离代理
           proxy_pass http://www.bbb.com:8080;
        }
    }
}
4.创建静态页面
echo www.zzhz.com index.html > /usr/share/nginx/html/index.html 

  

5.添加nginx和tomcat和客户端hosts解析
192.168.80.100 www.magedu.net www.zzhz.com
192.168.80.140 www.aaa.com  www.bbb.com

6.测试
[root@localhost6B ~]# curl www.magedu.net
/usr/local/tomcat/webapps/ROOT/index.html
[root@localhost6B ~]# curl www.magedu.net/test/
/data/test/index.html
[root@localhost6B ~]# curl www.magedu.net/test/index.jsp
www.aaa.com/test/index.jsp

[root@localhost6B ~]# curl www.zzhz.com
www.zzhz.com index.html 
[root@localhost6B ~]# curl www.zzhz.com/index.jsp
www.bbb.com/index.jsp

  

posted @ 2022-08-07 13:10  yuanbangchen  阅读(67)  评论(0编辑  收藏  举报