tomcat多虚拟主机配置+nginx反向代理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | 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 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 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 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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 |
分类:
Tomcat
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~