Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8584261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:43:57+00:00 2026-06-11T21:43:57+00:00

I want to set up a proxy running on tomcat for openlayers, so I

  • 0

I want to set up a proxy running on tomcat for openlayers, so I followed these steps:

  1. Downloaded the proxy.cgi file from the OpenLayers web site:

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

Here is the code:

#!c:/Python27/python.exe


"""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','localhost:6901']

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]
    else:
        url = "http://www.openlayers.org"
else:
    fs = cgi.FieldStorage()
    url = fs.getvalue('url', "http://www.openlayers.org")

try:
    host = url.split("/")[2]
    if allowedHosts and not host in allowedHosts:
        print "Status: 502 Bad Gateway"
        print "Content-Type: text/plain"
        print
        print "This proxy does not allow you to access that location (%s)." % (host,)
        print
        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)
        else:
            y = urllib2.urlopen(url)

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

        print y.read()

        y.close()
    else:
        print "Content-Type: text/plain"
        print
        print "Illegal request."

except Exception, E:
    print "Status: 500 Unexpected Error"
    print "Content-Type: text/plain"
    print 
    print "Some unexpected error occurred. Error text was:", E
  1. I have my tomcat at port 6901, so I modified the proxy.cgi file to include my domain in the allowedHosts list:

    allowedHosts = [‘localhost:6901’]

  2. I copied the proxy.cgi file to the following folder:

    $TOMCAT_PATH$/webapps/myApp/WEB-INF/cgi/

  3. Modified the file web.xml of the web app by adding the sections below the file at

    $TOMCAT_PATH$/webapps/myApp/WEB-INF/web.xml

<servlet> 
    <servlet-name>cgi</servlet-name> 
    <servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class> 
    <init-param> 
        <param-name>debug</param-name> 
        <param-value>0</param-value> 
    </init-param> 
    <init-param> 
        <param-name>cgiPathPrefix</param-name> 
        <param-value>WEB-INF/cgi</param-value> 
    </init-param> 
    <init-param> 
        <param-name>executable</param-name> 
        <param-value>c:\python25\python.exe</param-value> 
    </init-param> 
    <init-param> 
        <param-name>passShellEnvironment</param-name> 
        <param-value>true</param-value> 
    </init-param> 
    <load-on-startup>5</load-on-startup> 
</servlet> 

<servlet-mapping> 
<servlet-name>cgi</servlet-name> 
<url-pattern>/cgi-bin/*</url-pattern> 
</servlet-mapping>

Comment: the “param-value” for the “executable” parameter has to contain the path to your Pyhton installation. (it does!)

  1. Modified the file context.xml of my web app by adding the element below, file at $TOMCAT_PATH$/webapps/myApp/META-INF/context.xml

  2. Restarted Tomcat

  3. To use the proxy with OpenLayers, included this single line into the code:

    OpenLayers.ProxyHost = “/yourWebApp/cgi-bin/proxy.cgi?url=”;

But the proxy isn’t working! When I try to use it like:

/myApp/cgi-bin/proxy.cgi?url=labs.metacarta.com 

I get this error:

Some unexpected error occurred. Error text was: list index out of range

I think it’s related to os.environ[“REQUEST_METHOD”], but I don’t know how it’s related.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:43:58+00:00Added an answer on June 11, 2026 at 9:43 pm

    The problem appears to be in your allowedHosts line. It should include the hosts that you want to connect to over the proxy (e.g. allowedHosts = ['labs.metacarta.com'])

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to set up a reverse proxy from one of our intranet IIS
i want set my own web proxy in google chrome to get all the
I want to set up an FTP connection using a proxy server with Apache's
I'm using wget to grab a something from the web, but I don't want
I want to set a proxy in C#.NET, the thing is, how would I
I basically want to set up a proxy server using Java which will capture
Situation: running a Google App Engine site with my static content's default_expiration set to
I want set interfaceOrientation in one UIView as LandscapeLeft and Portrait in other UIView.
i want set the visibility to itemized overlay in map view. if the zoom
I want set Listbox background to transparent but not working Is there any idea?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.