本文介绍了在Apache启用CORS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图启用CORS但不workign我。我正在runnign的CentOS 6.5与Apache。 aplication字preSS。我曾尝试以下。


  • 在模板文件中设置标题


  • 的.htaccess

    头设置访问控制允许来源*


重新启动Apache的。我仍然得到错误:

 跨域请求阻止:同源策略不允许在https://gateway.spectrumasa.com/dev/mcmap/test-geosml3.kmz读取远程资源。这可以由资源移动到相同域或启用CORS固定。

我想创建geoxml3鼠标悬停,而不是点击 KML多边形工具提示

下面是code目前我有我的模板。

 <! - <?脚本类型=文/ JavaScript的SRC =< = get_site_url();> /可湿性粉剂内容/主题/ twentytwelve-孩子/ JS / geoxml3.js.1>< / SCRIPT>
<脚本类型=文/ JavaScript的SRC =< = get_site_url();> /wp-content/themes/twentytwelve-child/js/ProjectedOverlay.js?>< / SCRIPT> - >
&LT;脚本类型=文/ JavaScript的 src=\"http://google-maps-utility-library-v3.google$c$c.com/svn/trunk/infobubble/src/infobubble.js\"></script>
&LT;脚本类型=文/ JavaScript的SRC =HTTP://geoxml3.google$c$c.com/svn/branches/polys/geoxml3.js&GT;&LT; / SCRIPT&GT;
&LT;脚本类型=文/ JavaScript的SRC =HTTP://geoxml3.google$c$c.com/svn/trunk/ProjectedOverlay.js&GT;&LT; / SCRIPT&GT;
?&LT; PHP的标题(访问控制允许来源:*');?&GT;
&LT;脚本类型=文/ JavaScript的&GT;
VAR geoXmlDoc = NULL;
VAR地图= NULL;
jQuery的(文件)。就绪(函数(){
VAR myOptions = {
        中心:新google.maps.LatLng(-19.5968657,-40.7717683)
        变焦:6,
        mapTypeId设为:google.maps.MapTypeId.ROADMAP
    };
    地图=新google.maps.Map(的document.getElementById(map_canvas的),myOptions);    VAR geoXml =新geoXML3.parser({
        地图:地图,
        singleInfoWindow:真实,
        afterParse:useTheData
    });
    geoXml.parse('https://gateway.spectrumasa.com/dev/mcmap/test-geosml3.kmz');
//警报(完成初始化);
}
);
    功能useTheData(DOC){
    //地理数据处理放在这里,用doc对象的JSON属性
    geoXmlDoc =文档;
    对于(VAR I = 0; I&LT; D​​OC [0] .placemarks.length;我++){
        VAR标= DOC [0] .placemarks [I]
        polygonMouseover(placemark.polygon,placemark.name);
        //执行console.log(DOC [0] .markers [I] .title伪);
        。jQuery的('#map_text')追加(文件[0] .placemarks [I]。名称+',');
    }
    };
VAR IB =新InfoBubble({
          shadowStyle:0,
          填充:0,
          的backgroundColor:'白',
          borderRadius:4,
          arrowSize:0,
          边框宽度:1,
          BORDERCOLOR:'黑',
          disableAutoPan:真实,
          hideCloseButton:真实,
          arrowPosition:50,
          arrowStyle:0
        });
功能polygonMouseover(聚,文字){
   google.maps.event.addListener(聚,'鼠标悬停',函数(EVT){
     ib.setContent(文本);
     ib.setPosition(evt.latLng);
     ib.setMap(地图);
     ib.open()
   });
   google.maps.event.addListener(聚,'鼠标移开,功能(EVT){
     ib.close()
   });
}
&LT; / SCRIPT&GT;&LT; META NAME =视CONTENT =初始规模= 1.0,用户可扩展性=无&GT;&LT; D​​IV ID =容器类=three_column_middle&GT;
    &LT; D​​IV ID =内容角色=主&GT;
        &LT;?PHP的如果($&后GT; post_parent)?{&GT;
        &LT; D​​IV CLASS =SECTION_TITLE&GT;&LT; PHP的回声get_the_title(); ?&GT;&LT; / DIV&GT;
        &LT; PHP}&GT?;
        &LT; D​​IV CLASS =第二conent容器&GT;
            ?&LT;而PHP(have_posts()):the_post(); ?&GT;
                &LT; PHP get_template_part('内容','页面'); ?&GT;
                &LT; PHP comments_template('',真); ?&GT;
            &LT; PHP ENDWHILE; //循环结束。 ?&GT;            &LT; D​​IV ID =map_canvas的风格=WIDTH:600px的;高度:500像素;&GT;&LT; / DIV&GT;    &LT; D​​IV ID =map_text&GT;&LT; / DIV&GT;
        &LT; / DIV&GT;
    &LT; / DIV&GT;&LT;! - #内容 - &GT;&LT; / DIV&GT;&LT;! - #container的 - &GT;&LT; PHP get_sidebar('右'); ?&GT;
&LT; / DIV&GT;&LT; / DIV&GT;&LT;! - #3列容器 - &GT;&LT; PHP get_footer(); ?&GT;

在网关它仅仅是向公众开放的代理查找

  ProxyPassReverse的/ dev / mcmap http://172.16.0.29/mcmap
的ProxyPass的/ dev / mcmap http://172.16.0.29/mcmap
ProxyPassReverse的/ dev / knowledgemap http://172.16.0.29/mcmap
的ProxyPass的/ dev / knowledgemap http://172.16.0.29/mcmap

看完后我已经加入

 &LT; LocationMatch的/ dev / mcmap&GT;
   标题加上访问控制允许来源,*
   头中设置访问控制,允许 - 头原产地,X-要求-着,内容类型,接受
&LT; / LocationMatch&GT;


解决方案

这似乎进入之后已经wqorked

 &LT; LocationMatch的/ dev / mcmap&GT;
   标题加上访问控制允许来源,*
   头中设置访问控制,允许 - 头原产地,X-要求-着,内容类型,接受
&LT; / LocationMatch&GT;

在代理和结算本地服务器的缓存。

I am trying to enable CORS but it is not workign for me. i am runnign centos 6.5 with apache. aplication wordpress. i have tried the following.

restarted apache. still i get error:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://gateway.spectrumasa.com/dev/mcmap/test-geosml3.kmz. This can be fixed by moving the resource to the same domain or enabling CORS.

I am trying to create geoxml3 kml polygon tooltip on mouseover instead of click

Below is the code i currently have on my template.

<!-- <script type="text/javascript" src="<?=get_site_url(); ?>/wp-content/themes/twentytwelve-child/js/geoxml3.js.1"></script>
<script type="text/javascript" src="<?=get_site_url(); ?>/wp-content/themes/twentytwelve-child/js/ProjectedOverlay.js"></script>-->
<script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobubble/src/infobubble.js"></script>
<script type="text/javascript" src="http://geoxml3.googlecode.com/svn/branches/polys/geoxml3.js"></script>
<script type="text/javascript" src="http://geoxml3.googlecode.com/svn/trunk/ProjectedOverlay.js"></script>
<?php header('Access-Control-Allow-Origin: *');?>
<script type="text/javascript">
var geoXmlDoc = null;
var map = null;
jQuery(document).ready(function () {
var myOptions = {
        center: new google.maps.LatLng(-19.5968657,-40.7717683),
        zoom: 6,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var geoXml = new geoXML3.parser({
        map: map,
        singleInfoWindow: true,
        afterParse: useTheData
    });
    geoXml.parse('https://gateway.spectrumasa.com/dev/mcmap/test-geosml3.kmz');
// alert("done init");
}
);
    function useTheData(doc) {
    // Geodata handling goes here, using JSON properties of the doc object
    geoXmlDoc = doc;
    for (var i = 0; i < doc[0].placemarks.length; i++) {
        var placemark = doc[0].placemarks[i];
        polygonMouseover(placemark.polygon,placemark.name);
        // console.log(doc[0].markers[i].title);
        jQuery('#map_text').append(doc[0].placemarks[i].name + ', ');
    }
    };
var ib = new InfoBubble({
          shadowStyle: 0,
          padding: 0,
          backgroundColor: 'white',
          borderRadius: 4,
          arrowSize: 0,
          borderWidth: 1,
          borderColor: 'black',
          disableAutoPan: true,
          hideCloseButton: true,
          arrowPosition: 50,
          arrowStyle: 0
        });
function polygonMouseover(poly, text) {
   google.maps.event.addListener(poly,'mouseover', function(evt) {
     ib.setContent(text);
     ib.setPosition(evt.latLng);
     ib.setMap(map);
     ib.open()
   });
   google.maps.event.addListener(poly,'mouseout', function(evt) {
     ib.close()
   });
}
</script>

<meta name="viewport" content="initial-scale=1.0, user-scalable=no">



<div id="container" class="three_column_middle">
    <div id="content" role="main">
        <?php  if($post->post_parent){?>
        <div class="section_title"><?php echo get_the_title(); ?></div>
        <?php }?>
        <div class="second-conent-container">
            <?php while ( have_posts() ) : the_post(); ?>
                <?php get_template_part( 'content', 'page' ); ?>
                <?php comments_template( '', true ); ?>
            <?php endwhile; // end of the loop. ?>

            <div id="map_canvas" style="width:600px;height:500px;"></div>

    <div id="map_text"></div>
        </div>
    </div><!-- #content -->

</div><!-- #container -->

<?php get_sidebar('right'); ?>
</div></div><!-- #3 column container -->

<?php get_footer(); ?>

On gateway it is just a proxy lookup for public access

ProxyPassReverse /dev/mcmap http://172.16.0.29/mcmap
ProxyPass /dev/mcmap http://172.16.0.29/mcmap
ProxyPassReverse /dev/knowledgemap http://172.16.0.29/mcmap
ProxyPass /dev/knowledgemap http://172.16.0.29/mcmap

After reading http://g00se.org/2013/07/reverse-proxy-with-cors.html I have added

<LocationMatch "/dev/mcmap">
   Header add "Access-Control-Allow-Origin" "*"
   Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
</LocationMatch>
解决方案

This seemed to have wqorked after entering

<LocationMatch "/dev/mcmap">
   Header add "Access-Control-Allow-Origin" "*"
   Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
</LocationMatch>

on proxy and clearing local server cache.

这篇关于在Apache启用CORS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 12:43
查看更多