日期:2014-05-17  浏览次数:21207 次

apache转发 js 跨域

安装Apache HTTP Server

打开apache安装目录的conf文件夹下的httpd.conf

1、将以下两行前的注释字符 # 去掉:

#LoadModule proxy_module modules/mod_proxy.so

#LoadModule proxy_http_module modules/mod_proxy_http.so

2、在httpd.conf 文件的最后加上转发规则

例如:

ProxyPass /cas http://192.168.0.206:9090/cas

ProxyPassReverse /cas? http://192.168.0.206:9090/cas

/cas开头的请求转发到206服务器9090端口的cas

转自http://wenku.baidu.com/view/380eef63caaedd3383c4d38f.html

?

QA:

1.windows不能在本地计算机启动apache2.2解决

?? 打开httpd.conf文件 搜索 "ServerAdmin "改为 "#ServerAdmin ",保存退出

?

?

以下为本人做的js跨域实验配置:

1.httpd.conf最后添加

#加载代理(proxy)模块
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

#配置监听端口(如果用默认端口号80的话,则tomcat不用添加proxyPort配置)
Listen 3004

#配置虚拟站点
<VirtualHost *:3004>
    ServerAdmin webmaster@dummy-host.localhost
    DocumentRoot "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs"
    ServerName localhost
    ServerAlias localhost
    #ErrorLog "logs/VirtualHost3004-error.log"
    #CustomLog "logs/VirtualHost3004-access.log" common
    <Directory "C:\Program Files\Apache Software Foundation\Apache2.2\htdocs">  
        Options Indexes FollowSymLinks
        AllowOverride None
        Order allow,deny
        Allow from all
    </Directory>
    
    ProxyPass  /JsCrossDomainChild http://127.0.0.1:8089/JsCrossDomainChild
    ProxyPassReverse /JsCrossDomainChild http://127.0.0.1:8089/JsCrossDomainChild
    ProxyPass  /JsCrossDomainParent http://localhost:8088/JsCrossDomainParent
    ProxyPassReverse /JsCrossDomainParent http://localhost:8088/JsCrossDomainParent
		
</VirtualHost>

?

2.tomcat/conf/server.xml添加 proxyPort="3004"

<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
    <Connector port="8088" maxHttpHeaderSize="8192" proxyPort="3004" ...

?

3.parent.jsp

<html>
  <head>
	<script type="text/javascript">
	  function xxForChild(){
		document.getElementById('xx').innerHTML += "abc<BR>";
	  }
	</script>
  </head>
  <body >
    <input type="button" value="getChildContent" onclick="alert(document.frames['fr1'].document.getElementsByTagName('h1')[0].firstChild.data)"/>
    <div id="xx">p</div>
    <iframe id="fr1" name="fr1" height="700px" width="700px" src ="http://localhost:3004/JsCrossDomainChild/index.jsp" frameborder="1" width="100%" scrolling="no"></iframe>
  </body>
</html>

?

4.child.jsp

  <body >
    <input type="button" value="parent.xxForChild();" onclick="parent.xxForChild();"/><br>
    <h1>h1的内容</h1> 
  </body>

?5.访问http://localhost:3004/JsCrossD