一、下载安装tomcat
1、解压
[root@iZ28zo01ceuZ bin]# mkdir /usr/local/tomcat
[root@iZ28zo01ceuZ bin]# cd /usr/local/tomcat
[root@iZ28zo01ceuZ bin]# tar -zxvf /software/apache-tomcat-7.0.54.tar.gz
2、在控制台输入
[root@iZ28zo01ceuZ bin]#cd /usr/local/tomcat/bin/
[root@iZ28zo01ceuZ bin]#vim catalina.sh
在编辑里面加入
ATALINA_HOME=/usr/tomcat/
3、启动
[root@iZ28zo01ceuZ bin]# ./startup.sh
4、启动成功提示:
1 2 3 4 5 6 Using CATALINA_BASE: /var/tomcat/tomcatyey Using CATALINA_HOME: /var/tomcat/tomcatyey Using CATALINA_TMPDIR: /var/tomcat/tomcatyey/temp Using JRE_HOME: /usr/lib/jvm/jre-1.8.0-openjdk Using CLASSPATH: /var/tomcat/tomcatyey/bin/bootstrap.jar:/var/tomcat/tomcatyey/bin/tomcat-juli.jar Tomcat started. 其中查找对应tomcat进程查找:
[root@iZ28zo01ceuZ bin]# ps -ef |grep tomcat
找到对应的pid即可操作Kill
[root@iZ28zo01ceuZ bin]# kill pid -9
5、部署web项目到tomcat中
二、nginx配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 server { listen 80; server_name *.beizhiyuan.com.cn; #绑定域名 location / { proxy_pass http://127.0.0.1:8086;
proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }
}
/usr/local/nginx/sbin/nginx -s reload
nginx已经重启成功
可以访问了。如:http://lmjxxfsyey.beizhiyuan.com.cn/ 就是使用此方法部署的,在后台判断host来获取对应域名所对应的数据。
java代码的实现:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { final HttpServletRequest req = (HttpServletRequest) request; final HttpServletResponse res = (HttpServletResponse) response; String requestPage =req.getHeader("Host");
if (req.getRequestURL().indexOf("http://app.beizhiyuan.com.cn") < 0
&& req.getRequestURL().indexOf("http://shop.beizhiyuan.com.cn") < 0
&&req.getRequestURL().indexOf("http://www.beizhiyuan.com.cn") < 0
&&req.getRequestURL().indexOf("http://beizhiyuan.com.cn")<0) {
int endIndex = requestPage.indexOf(".");
String secondDomainName = requestPage.substring(0, endIndex);
req.getSession().setAttribute("schoolurl",secondDomainName);
}
chain.doFilter(request, response);
}