Hi, I am posting this because I faced difficulty to configure ProxyHost on the windows platform to resolve the Cross Domain issue on the windows platform. The issue is discussed widely but there are no clear instructions available.
From the OpenLayers Wiki, due to security restrictions in JavaScript, it is not possible to retrieve information from remote domains via an XMLHttpRequest.
What we were getting was when the tooltip layer was coming into the scale tooltips would either not appear or you would receive the error message “Access is denied”.
The article details how to resolve the Remote Server restriction with the OpenLayers XMLHttpRequest.
Pre-requisite
Apache should be installed on the server where the client application is installed. In this case this web server IP is 193.120.94.133 and we are trying to resolve cross domain issue with the server with an IP 193.120.94.100.
Apache on 193.120.94.133 server is installed in C:\Apache folder
So here you go!
Install Proxy.CGI script file in Apache
If the OpenLayers.ProxyHost variable is not set to a valid proxy host, requests are sent directly to the remote servers. In most cases, the result will be a security exception, although this exception often occurs silently.
An example proxy host script is available here: trunk/openlayers/examples/proxy.cgi
The proxy script is configured for the Windows environment.
- Copy proxy.cgi to C:\Apache\cgi-bin folder.
- Edit the first line. Change the first line from #!/usr/bin/env python to #!/Python27/python
Note that it is assumed here that the Python is/will be installed in C:\Python27 folder.
3. Change the allowHosts array in the script. Change it from
|
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’] |
to
|
allowedHosts = [‘www.openlayers.org’, ‘openlayers.org’, ‘www.openstreetmap.org’, ,’193.120.94.100‘] |
Note that the cross domain server domain name is included which in this case is 193.120.94.100
4. Save the file and close.
Install Python
- Download the installer from the link http://python.org/download/
- For this exercise, the following installer used was Python 2.7.3 Windows Installer.
- Install Python in C:\Python27 folder.
Edit httpd.conf
- Open C:\Apache\Conf\httpd.conf.
- Locate the line <Directory “Apache/htdocs”>
- Scroll down and change the line Options Indexes FollowSymLinks to Options Indexes FollowSymLinks ExecCGI
- Locate the line <IfModule mime_module>
- Scroll down and change the line #AddHandler cgi-script .cgi to AddHandler cgi-script .cgi .py
Restart the Apache Service
Restart the Apache service either from the control panel or running apache-restart.bat file.
Test Python web page.
- Create a file test.py using notepad.
- Copy the following lines into the file.
|
#!/Python27/python print “Content-type: text/html” print “<html><head>” print “” print “</head><body>” print “Test Page” print “</body></html>” |
3. Copy the test.py into the C:\Apache\htdocs folder
4. Test the web page by using the URL http://193.120.94.133:8080/test.py (8080 is the port no configured for Apache). If the page runs successfully you should be seeing Test Page in the browser.
Edit the default.aspx in the client application
- In the client application add the following code in the map loading JavaScript in the beginning:
|
function LoadOpenLayersMap() { try { OpenLayers.ProxyHost = “http://193.120.94.133:8080/cgi-bin/proxy.cgi?url=”; |
Test the client application
Test the client application. The map should not show any error and the tooltips should appear when cursor hovers over a feature when in scale range.
That is it!
hello there..
I would just like to ask if where am I going to put my proxy.cgi if I am using tomcat 6 and geoserver?..as I can see from your example it is right after the Apache folder (C:\Apache\cgi-bin),In my tomcat I haven’t seen a folder cgi-bin,,am I going to create that folder?
LikeLike
Hi There,
My first thoughts are two possibilities for the “problem.”
Apache was not completely/properly installed. Perhaps there was an error in the installation process.
Apache was installed properly, but the location of the conf file(s) and such are different than the documentation you are looking at.
Which OS/distro are you working with? That makes a lot of difference.
can you check your httpd.conf and locate ScriptAlias /cgi-bin/ this will show you the location of the cgi-bin directory.
Regards,
Vijay
LikeLike
Hi, well mine is HTTP server and the site http://httpd.apache.org should be looked at to download correct binaries if yours is too.
LikeLike
I think my server is up and running. I am using windows 7. I just installed Tomcat 6 and there’s no cgi-bin folder there. Do you have any ideas on where am I going to put the file? I haven’t seen also the httpd.conf file.
LikeLike