I'm having trouble with the standard proxy.cgi written in Python for OpenLayers. Here's my code:

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

"""This is a blind proxy that we use to get around browser
restrictions that prevent the Javascript from loading pages not on the
same server as the Javascript.  This has several problems: it's less
efficient, it might break some sites, and it's a security risk because
people can use this proxy to browse the web and possibly do bad stuff
with it.  It only loads pages via http and https, but it can load any
content type. It supports GET and POST requests."""

import urllib2
import cgi
import sys, os

# Designed to prevent Open Proxy type stuff.

allowedHosts = ['www.openlayers.org', 'openlayers.org', 
                'labs.metacarta.com', 'world.freemap.in', 
                'prototype.openmnnd.org', 'geo.openplans.org',
                'sigma.openplans.org', 'demo.opengeo.org',
                'www.openstreetmap.org', 'sample.azavea.com',
                'v2.suite.opengeo.org', 'v-swe.uni-muenster.de:8080', 
                'vmap0.tiles.osgeo.org', 'www.openrouteservice.org',
                'dcdu.municipiodeslp.gob.mx:8082', 'www.ssn.unam.mx',
                'localhost','localhost:8082', 'localhost:80','','']

method = os.environ["REQUEST_METHOD"]

if method == "POST":
    qs = os.environ["QUERY_STRING"]
    d = cgi.parse_qs(qs)
    if d.has_key("url"):
        url = d["url"][0]
        url = "http://www.openlayers.org"
    fs = cgi.FieldStorage()
    url = fs.getvalue('url', "http://www.openlayers.org")

    host = url.split("/")[2]
    if allowedHosts and not host in allowedHosts:
        print "Status: 502 Bad Gateway"
        print "Content-Type: text/plain"
        print "This proxy does not allow you to access that location (%s)." % (host,)
        print os.environ

    elif url.startswith("http://") or url.startswith("https://"):

        if method == "POST":
            length = int(os.environ["CONTENT_LENGTH"])
            headers = {"Content-Type": os.environ["CONTENT_TYPE"]}
            body = sys.stdin.read(length)
            r = urllib2.Request(url, body, headers)
            y = urllib2.urlopen(r)
            y = urllib2.urlopen(url)

        # print content type header
        i = y.info()
        if i.has_key("Content-Type"):
            print "Content-Type: %s" % (i["Content-Type"])
            print "Content-Type: text/plain"

        print y.read()

        print "Content-Type: text/plain"
        print "Illegal request."

except Exception, E:
    print "Status: 500 Unexpected Error"
    print "Content-Type: text/plain"
    print "Some unexpected error occurred. Error text was:", E

The odd thing is that I am able to receive a GeoRSS feed through the same proxy but not a WFS from GeoServer as shown below:

enter image description here enter image description here enter image description here

Even though 'localhost:8082' is added to my 'allowedHosts', I receive a '502 Bad Gateway' error. I've looked at many questions on proxy.cgi and a tutorial but I still have no idea what's wrong.

I'm running Apache on XAMPP on port 80 while GeoServer is on port 8082.


Here's what my "Workspace" in GeoServer is:

enter image description here

and the layer is registering as WFS:

enter image description here

And if I browse to the WFS at:


I receive xml:

<?xml version="1.0"?>
<xsd:schema xmlns:cite="http://www.opengeospatial.net/cite" xmlns:gml="http://www.opengis.net/gml" xmlns:it.geosolutions="http://www.geo-solutions.it" xmlns:mx="mx" xmlns:nurc="http://www.nurc.nato.int" xmlns:sanluis="sanluis" xmlns:sde="http://geoserver.sf.net" xmlns:sf="http://www.openplans.org/spearfish" xmlns:slp="slp" xmlns:test="http://test" xmlns:test_php="http://test_php" xmlns:tiger="http://www.census.gov" xmlns:tlx="tlx" xmlns:topp="http://www.openplans.org/topp" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:zac="http://localhost:80/Atlas_TLX/zac" elementFormDefault="qualified" targetNamespace="http://localhost:80/Atlas_TLX/zac">
<xsd:import namespace="http://www.opengis.net/gml" schemaLocation="http://localhost:8082/geoserver/schemas/gml/3.1.1/base/gml.xsd"/>
<xsd:complexType name="gcoloniaType">
        <xsd:extension base="gml:AbstractFeatureType">
                <xsd:element maxOccurs="1" minOccurs="0" name="gid" nillable="true" type="xsd:long"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="edo_cve" nillable="true" type="xsd:int"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="regcat_cve" nillable="true" type="xsd:int"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="mun_cve" nillable="true" type="xsd:int"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="zoncat_cve" nillable="true" type="xsd:int"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="loc_cve" nillable="true" type="xsd:int"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="col_id" nillable="true" type="xsd:long"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="col_area" nillable="true" type="xsd:decimal"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="catcol_nombre" nillable="true" type="xsd:string"/>
                <xsd:element maxOccurs="1" minOccurs="0" name="col_geom" nillable="true" type="gml:GeometryPropertyType"/>
<xsd:element name="gcolonia" substitutionGroup="gml:_Feature" type="zac:gcoloniaType"/>

I'm beginning to think it's a problem with OpenLayers. Here's how I'm adding it to the map:

gcolonia = new OpenLayers.Layer.Vector("gcolonia", {
                                strategies: [new OpenLayers.Strategy.Fixed()],
                                protocol: new OpenLayers.Protocol.WFS({
                                    srsName: new OpenLayers.Projection("EPSG:4326"),
                                    url: "http://localhost:8082/geoserver/wfs",
                                    featureType: "gcolonia",
                                    featureNS: "http://localhost:80/Atlas_TLX/zac",
                                    geometryName: "col_geom"

                                visibility: false

Newest Update

Browsing to http://localhost/cgi-bin/proxy.cgi?url=http://www.ssn.unam.mx -> fine Browsing to http://localhost/cgi-bin/proxy.cgi?url=http://localhost:8082/geoserver/web ->

This proxy does not allow you to access (localhost:8082).

Yet, my proxy.cgi contains that location as shown above. My cgi-bin is located in xampp/cgi-bin. I've also cleared my browser cache.

Any thoughts?

  • I think you may have wanted to post a image but it did not come through. Is WFS enabled?
    – Ralph Dell
    Commented Aug 28, 2014 at 12:10
  • I just added more information about the WFS. I believe it is enabled.
    – Zach
    Commented Aug 28, 2014 at 15:36
  • Here are a couple of suggestions. For my FeatureNS: I only use my domain, which in your case would be "localhost". Are you sure your geometryName is "col_geom"? I do not use GeoRSS so my help is limited.
    – Ralph Dell
    Commented Aug 28, 2014 at 18:18
  • I can accept calls from other domains but not from geoserver (i.e. can display from a GeoRSS source but not a WFS from geoserver). Sorry if I wasn't clear. My geometryName is "col_geom" oddly enough. I tried changing my "workspace URI" (featureNS) to "localhost" with no luck...
    – Zach
    Commented Aug 28, 2014 at 18:48
  • stupid question, but why did you replace localhost by mylocalhost in the query? and what do you get when you try to access ../cgi-bin/proxy.cgi?url=http://localhost:8082/geoserver/web? Also is your proxy.cgi and Geoserver on the same system? Commented Aug 29, 2014 at 2:20


Your Answer

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

Browse other questions tagged or ask your own question.