Joan Natalie
Joan Natalie

Reputation: 330

Failed to execute proxy.cgi on virtualhost apache

i've been trying to execute proxy.cgi from openlayers on my computer using windows 7 and xampp. when i tried to using localhost/mymaps/cgi-bin/proxy.cgi it execute perfectly.

but when i tried to execute using virtualhost it came up with

Server error!

The server encountered an internal error and was unable to complete your request.

Error message: couldn't create child process: 720002: proxy.cgi

i look at error log it said

[Thu Feb 06 14:24:16 2014] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified.  : couldn't create child process: 720002: proxy.cgi
[Thu Feb 06 14:24:16 2014] [error] [client 127.0.0.1] (OS 2)The system cannot find the file specified.  : couldn't spawn child process: C:/xampp/cgi-bin/proxy.cgi

this is my httpd-vhosts.conf file

<VirtualHost *:80>
    ServerAdmin [email protected]
    DocumentRoot "C:\xampp\htdocs\sidik"
    ServerName sidik.com
    ServerAlias sidik.com
    <Directory "C:\xampp\htdocs\sidik">
    Order allow,deny
    Allow from all
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    </Directory>
</VirtualHost>

this is my proxy.cgi

#!/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.google.co.id','www.openlayers.org','202.124.205.123:81/~vaonline', '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','172.20.110.20:83','172.20.110.20' 
                'vmap0.tiles.osgeo.org', 'www.openrouteservice.org', '172.20.32.11:8080']

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

what have i done wrong?

Upvotes: 3

Views: 1781

Answers (1)

user28864
user28864

Reputation: 3463

Although this maybe coming at a late hour, however here is something that worked for me anyway. By specifying the location of my python executable application on windows, with the following code like so; #!c:/Python27/python.exe at the top of the cgi file in place of #!/Python27/python.exe -u in your own case and also making sure I had this configuration (in my apache httpd.conf configuration);

<Directory "C:/xampp/cgi-bin">
  AllowOverride All
  Options None
  Require all granted
</Directory>

I was able to get the cgi file to work. hope this helps

Upvotes: 2

Related Questions