1、下載安裝tomcatjava
一、解壓nginx
[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
二、在控制檯輸入web
[root@iZ28zo01ceuZ bin]#cd /usr/local/tomcat/bin/ [root@iZ28zo01ceuZ bin]#vim catalina.sh
在編輯裏面加入apache
ATALINA_HOME=/usr/tomcat/
三、啓動bootstrap
[root@iZ28zo01ceuZ bin]# ./startup.sh
四、啓動成功提示:vim
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進程查找:tomcat
[root@iZ28zo01ceuZ bin]# ps -ef |grep tomcatapp
找到對應的pid便可操做Killjvm
[root@iZ28zo01ceuZ bin]# kill pid -9ide
五、部署web項目到tomcat中
2、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; }
}
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); }