nginx整合tomcat实现域名泛解析

一、下载安装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);
}

转载于:https://my.oschina.net/u/1052192/blog/719884

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值