Here is my code for getting a WMS layer in OpenLayers from Geoserver.

var wfs2 = new OpenLayers.Layer.Vector("WFS", {
                    strategies: [new OpenLayers.Strategy.Fixed()],
                    protocol: new OpenLayers.Protocol.WFS({          
                    version: "1.1.0",
                    url: "http://localhost:8080/geoserver/wfs",            
                    featurePrefix: "topp",
                    featureType: "states",
                    featureNS: "www.openplans.org/topp",
                    srsName: "EPSG:4326",
                    geometryName: "position"

So i get this problem in developer tools for chrome :

XMLHttpRequest cannot load http://localhost:8080/geoserver/wfs. Origin null is not allowed by Access-Control-Allow-Origin. 

in developer tools for chrome

I saw that people recommend to set up a proxy, but my .html is in the geoserver/data_dir/www folder, and don't call external urls.

I however tried it, so I created the folder cgi-bin in /usr/local/geoserver/cgi-bin/, where i put the proxy code I found here :http://trac.osgeo.org/openlayers/wiki/FrequentlyAskedQuestions#ProxyHost

And then I added in the cript of my .html this : OpenLayers.ProxyHost = "/cgi-bin/proxy.cgi?url=";

But I then get this error in developer tools :

Failed to load resource file://localhost/cgi-bin/proxy.cgi?url=http%3A%2F%2Flocalhost%3A8080%2Fgeoserver%2Fwfs 

Probably the proxy is not in the right place, but I don't think the first problem (without problem) comes from here.

  • If your html file is in geoserver/data_dir/www folder, how are you calling it in your browser? what is teh Url in your Browser? Does it start with http:// or file://? May 24, 2013 at 5:43
  • I access it this way : file://localhost/usr/local/geoserver/data_dir/www/map2.html
    – Gabriel
    May 24, 2013 at 5:50

1 Answer 1


You should access it through http protocol. file protocol is not allowed with a WFS server. see this StackOverflow question.

To test geoserver WFS try GetCapabilities request.

For your case try this:


More info at geoserver manual


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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