nginx整合tomcat实现域名泛解析
2016-07-29 00:00
411 查看
摘要: nginx整合tomcat实现域名泛解析
一、下载安装tomcat
1、解压
2、在控制台输入
在编辑里面加入
3、启动
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;
}
可以访问了。如: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");
一、下载安装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); }
相关文章推荐
- nginx整合tomcat实现域名泛解析
- Nginx与Tomcat整合及跨域功能的实现
- 一,nginx与tomcat整合实现负载均衡
- nginx整合tomcat实现负载均衡/集群(可用版)
- 阿里云linux下Nginx整合Tomcat实现负载均衡集群
- 整合Tomcat和Nginx实现动静态负载均衡
- nginx+tomcat整合后获取真实IP
- 利用mod_proxy实现Apache和Tomcat整合负载均衡
- nginx + tomcat 集群配置详解, 实现负载均衡 URLRewrite Session复制
- Windows2003 Server 下 IIS与Tomcat的整合,实现ASP与JSP统一访问(支持多域名访问)
- windows下整合tomcat和nginx
- 用jk整合Apache和tomcat实现负载均衡
- linux下 apache与tomcat整合实现伪静态
- 用apache代理实现整合多个tomcat 推荐
- windows下整合 tomcat 和 nginx
- Ubuntu下基于Nginx实现Tomcat集群负载均衡
- apache整合tomcat实现web服务器的动静态资源的分离解析
- IIS5和Tomcat6整合,实现IIS5支持ASP(.NET)+PHP+JSP
- nginx+tomcat实现集群负载均衡(实现session复制)
- nginx+tomcat实现集群负载均衡(实现session复制)