iframe嵌套其它系统(跨域)页面且需要登录

iframe   页面嵌套 跨域 登录 切换容器

最近老项目因为数据库压力过大,需要把其中流程靠后的B功能模块拆分出来独立部署。APP上云、使用云数据库,这样不影响原数据库性能。

原项目:http://www.myproject.pro.cn/thirdPlat/login ,使用WAS容器,功能B拆分后上云需要使用tomcat容器,这样系统数据库链接的配置就需要改掉了。

这部分花费时间不多。

修改点:1 .原项目涉及数据连接的JAVA类和配置文件。

              2.tomcat的apache-tomcat-9.0.58\conf目录下的文件(context.xml、server.xml,web.xml)

context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
--><!-- The contents of this file will be loaded for each web application --><Context>

    <!-- Default set of monitored resources. If one of these changes, the    -->
    <!-- web application will be reloaded.                                   -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
    <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    <!--
    <Manager pathname="" />
    --> 
			<Resource auth="Container"
		name="jdbc/mydata" type="javax.sql.DataSource" 
		maxTotal="100" maxIdle="30" maxWaitMillis="10000" 
		driverClassName="net.sourceforge.jtds.jdbc.Driver"
		url="jdbc:jtds:sqlserver://192.168.1.1:1433/DB_mydata"
		username="root" password="111111" validationQuery="select 1"/> 

	<Resource auth="Container"
		name="jdbc/mydata" type="javax.sql.DataSource" 
		maxTotal="100" maxIdle="30" maxWaitMillis="10000" 
		driverClassName="net.sourceforge.jtds.jdbc.Driver"
		url="jdbc:jtds:sqlserver://192.168.1.1:1433/DB_mydata"
		username="root" password="111111" validationQuery="select 1"/> 
		
</Context>
server.xml

增加:
  <GlobalNamingResources>
    <!-- Editable user database that can also be used by
         UserDatabaseRealm to authenticate users
    --> 
<Resource auth="Container"
		name="jdbc/mydata" type="javax.sql.DataSource" 
		maxTotal="100" maxIdle="30" maxWaitMillis="10000" 
		driverClassName="net.sourceforge.jtds.jdbc.Driver"
		url="jdbc:jtds:sqlserver://192.168.1.1:1433/DB_mydata"
		username="root" password="111111" validationQuery="select 1"/> 

	<Resource auth="Container"
		name="jdbc/mydata" type="javax.sql.DataSource" 
		maxTotal="100" maxIdle="30" maxWaitMillis="10000" 
		driverClassName="net.sourceforge.jtds.jdbc.Driver"
		url="jdbc:jtds:sqlserver://192.168.1.1:1433/DB_mydata"
		username="root" password="111111" validationQuery="select 1"/> 
		 <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
  </GlobalNamingResources>


修改:
      <Context docBase="myproject" path="/myproject" reloadable="true" source="org.eclipse.jst.jee.server:myproject"/></Host>
web.xml

这里是增加一个ALLOW-FROM的地址的配置,解决跨域的问题的.可以网上找一下,就不贴出来了。

我拿到的阿里云服务器是一个空的服务器,所以去上面安装了JDK TOMCAT 一些其他的协议之类的,基本上是报错再去解决的问题比较简单,百度可以解决。

这样基本上把war包放到服务器然后tomcat启动服务器启动项目就可以访问了。

跨域问题:因为只是把其中一个功能模块独立部署,但是前端入口还在原来的系统,前台页面需要嵌套。涉及到原来的页面前端技术框架导航栏都是《iframe src=''》就想到用NGINX来解决跨域问题,很快就解决了。

新的云项目网址:http://www.newproject.pro.cn/newPlat/login 

我在本地验证的时候就是在本地装了NGINX新增一个监听端口:

本地http://localhost:8080/thirdPlat 链接》http://localhost:8081/thirdPlat 

然后nginx配置 http://localhost:8081/thirdPlat  代理的http://www.newproject.pro.cn/newPlat/login 

nginx-1.20.2\conf\nginx.conf

    server {
        listen       8001;
        server_name  http://你的地址;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

 
        location / { 
			proxy_hide_header X-Frame-Options;    
			add_header X-Frame-Options ALLOWALL; 
			proxy_pass http://新项目;

        }

这样跨域问题就解决了。很HAPPY是不是?

这样到中间件部门不允许使用NGINX,因为我们生产没有用。

后来想到不用中间件代理之类的直接后台技术解决。碰到不少问题

1.浏览器跨域报错,不允许链接。

2.上面问题解决后,嵌套页面登录后重定向到了登录页面

3.再解决,跳到了想要的页面,但是原系统的cookie丢失了。

后来发现还是使用中间件代理一下靠谱,让访问的域都一样。

因为我们生产是集群:比如生产登录地址是https://bbbbb.aa.cc/myp/login 

让中间件组配置了一个https://bbbbb.aa.cc:9000/myp/login ,就是新增了一个监听的端口9000.这样就解决了跨域的问题。

注意:一开始拆分的功能B部署文根和原项目不一致,也会导致原项目cookie丢失。保持一致:

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值