4

I am having problems getting WFS data to display on a map using OpenLayers/GeoExt/GeoServer.

I created a proxy script like on this page:

http://trac.osgeo.org/openlayers/browser/trunk/openlayers/examples/proxy.cgi

I have put this is file in C:\Program Files\GeoServer 2.0.2\webapps\geoserver.

I have changed the path at the top line of the file to read

#!C:/Python26/python.exe -u

I have also added the address of the machine that I want to allow to the file (10.0.0.155:8080) and added an environment variable for python (the machine is running Windows XP).

When I point to the proxy.cgi in a web browser it just displays the proxy.cgi file in the web browser, when from what I have read it should be showing the OpenLayers homepage.

Does anyone know how I can get this to work?

Regards,

James

1
  • 1
    Running a Python CGI script inside of Tomcat is probably not going to work like that. The script is designed for people using Apache HTTPD to host their sites, not Tomcat. You'll need to do something different. Commented Oct 13, 2010 at 14:18

4 Answers 4

2

GeoServer doesn't provide a CGI folder so you either need to put the proxy script in you main server's CGI folder (if you are using Apache to serve GeoServer to the web) or go with the GeoServer proxy plugin http://geoserver.org/display/GEOS/GeoServer+Proxy+Extension that provides the same functionality with in the GeoServer environment.

6
  • Thanks for the help. Do I have to add a MIME type for WFS in the GeoServer proxy extension or will the ones already set up cover me?
    – James S
    Commented Oct 13, 2010 at 15:49
  • I've never actually used it but I imagine it will work for WFS out of the box.
    – Ian Turton
    Commented Oct 13, 2010 at 18:48
  • My webserver and geoserver are on 10.0.0.155:8080. My PostGIS install is on on the same machine, using port 5432. What host do I need to add in the geoserver proxy extension to make this work? And do I have to add the OpenLayers.Proxy line in my web page?
    – James S
    Commented Oct 14, 2010 at 10:50
  • 1
    I don't think you need a proxy in that case. You would need a proxy if you were serving your web page from a different machine than the one that has GeoServer on it. (PostGIS is irrelevant).
    – Ian Turton
    Commented Oct 14, 2010 at 14:00
  • I had also same problem.I had geoserver on port 8080 ,glassfish on port 9999.My OS is Windows 7.WHere should i put the "proxy.cgi" file ??Since there is no cgi-bin folder..
    – Nahom_Pain
    Commented Nov 2, 2011 at 14:43
1

Yes. You have to add the OpenLayers.Proxy to your web page. Is your web server IIS or apache? in the script you need to add 10.1.1.155:8080. I would also add 10.1.1.155 to the script.

1
0

You need a local server like apache something like that then u add your project in htdocts in apache after that u can user proxy like that

OpenLayers.ProxyHost = "/gt/proxy.cgi?url=";

0

If you have access to both webservers it might be just easier to add the appropriate headers for your situation:

Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:Authorization, X-Requested-With
Access-Control-Allow-Methods:GET, OPTIONS
Access-Control-Allow-Origin:http://your.origin.domain

You'll notice the browser performing 2 request after that: the first is a OPTION type call, the second a GET (in this case)

I only know how to do this -for sure- in nginx, for a live working example see: http://m.bitless.be/

open the debugger/webtools (in chrome ctrl+shift+i) and check out the XHR section. spot the traffic layer. I've set it up in a way that all domains should be able to access it automatically.

## Only allow OPTIONS and HEAD and GET request methods
if ($request_method ~ ^(OPTIONS|HEAD)$ ) {
    add_header Access-Control-Allow-Origin $http_origin;
    add_header Access-Control-Allow-Methods "GET, OPTIONS";
    add_header Access-Control-Allow-Headers "Authorization, X-Requested-With";
    add_header Access-Control-Allow-Credentials "true";
    add_header Content-Length 0;
    add_header Content-Type text/plain;
    return 200;
}
if ($request_method ~ ^(GET)$ ) {
    add_header Access-Control-Allow-Origin $http_origin;
    add_header Access-Control-Allow-Methods "GET, OPTIONS";
    add_header Access-Control-Allow-Headers "Authorization, X-Requested-With";
    add_header Access-Control-Allow-Credentials "true";
}

It's an alternative answer for your question: "How can I get this to work". That's how I eventually did it, even after writing my own proxy script, I find this way to suit my goals better, not having to worry about crossdomain restrictions in openlayers.

Needless to say: you need access to all webservers serving layer data.

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.