Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

This question already has an answer here:

This is my code for my page (index.html)

            info = new OpenLayers.Control.WMSGetFeatureInfo({
            url: 'http://localhost:8080/geoserver/wms',
            title: 'get feature info',
            queryVisible: true,
            eventListeners: {
                getfeatureinfo: function (event) {
                    map.addPopup(new OpenLayers.Popup.FramedCloud(
                        "chicken",
                        map.getLonLatFromPixel(event.xy),
                        null,
                        event.text,
                        null,
                        true
                    ));
                }
            }
        });

        map.addControl(info);
        info.activate();

and it's proxy code : OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

But I see a 404 error. Can someone please help?

share|improve this question
    
Do you have a proxy.cgi file? and have the domains that you use for the wms been added to this? –  Peter Campbell Feb 21 '13 at 12:07
    
No i dont have a proxy.cgi file, should I? and i haven't apache server is it a problem ? –  ankaGeo Feb 21 '13 at 12:14
    
Yes - you will need a proxy.cgi file for a Proxy if you are using apache as the web server –  Peter Campbell Feb 21 '13 at 12:21
add comment

marked as duplicate by Devdatta Tengshe, Zachary, underdark Feb 21 '13 at 14:27

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

up vote 2 down vote accepted

If you are using apache as the web server, you can use a proxy file called proxy.cgi to get round the problem of cross-origin javascript security.

The following is taken from OpenLayers FAQs about the ProxyHost setting

Why do I need a ProxyHost?

Due to security restrictions in Javascript, it is not possible to retrieve information from remote domains via an XMLHttpRequest.

Classes like WFS and GeoRSS use XMLHTTPRequest to get their data. If they are querying a remote server (anything other than the machine hosting your page), you must install a proxy script somewhere web accessible on that machine. See below for how to set up your own ProxyHost.

If the OpenLayers.ProxyHost variable is not set to a valid proxy host, requests are sent directly to the remote servers. In most cases, the result will be a security exception, although this exception often occurs silently. How do I set up a ProxyHost?

An example proxy host script is available here: trunk/openlayers/examples/proxy.cgi

For the standard Apache configuration, you would place proxy.cgi into your /usr/lib/cgi-bin/ directory.

Once a proxy host script has been installed, you must then edit the OpenLayers.ProxyHost variable to match that URL.

Given the above standard Apache configuration:

OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

If you have done something like this, you should be able to visit:

 http://YourDomain.example.com/cgi-bin/proxy.cgi

The resulting content at that page should be the openlayers.org website.

If you get a 404 error instead, either the proxy script is not in the right location, or your webserver is not configured correctly.

A sample proxy.cgi file can be found here

If you are using something like tomcat/jetty for your web server, then you will probably use a jsp for the proxy file, an example proxy.jsp file can be found here

share|improve this answer
    
I'm trying to query feature info on geoserver WMS . I refered this openlayers example openlayers.org/dev/examples/getfeatureinfo-popup.html –  ankaGeo Feb 21 '13 at 12:37
    
In that example the GetFeatureInfo url is demo.opengeo.org/geoserver/wms whereas the web page is at openlayers.org/dev/examples/getfeatureinfo-popup.html. Therefore they need to go through a proxy (server side) to avoid a 404 –  Peter Campbell Feb 21 '13 at 13:58
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.